|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import fs from 'fs'; |
| 5 | +import path from 'path'; |
| 6 | +import { fileURLToPath } from 'url'; |
| 7 | + |
| 8 | +const __filename = fileURLToPath(import.meta.url); |
| 9 | +const __dirname = path.dirname(__filename); |
| 10 | + |
| 11 | +// Color definitions for package types |
| 12 | +const packageTypeColors = { |
| 13 | + 'Notifications': { fill: '#ffcdd2', stroke: '#c62828', color: '#280505' }, |
| 14 | + 'Observability': { fill: '#c8e6c9', stroke: '#2e7d32', color: '#142a14' }, |
| 15 | + 'Observability Extensions': { fill: '#e8f5e9', stroke: '#66bb6a', color: '#1f3d1f' }, |
| 16 | + 'Runtime': { fill: '#bbdefb', stroke: '#1565c0', color: '#0d1a26' }, |
| 17 | + 'Tooling': { fill: '#ffe0b2', stroke: '#e65100', color: '#331a00' }, |
| 18 | + 'Tooling Extensions': { fill: '#fff3e0', stroke: '#fb8c00', color: '#4d2600' } |
| 19 | +}; |
| 20 | + |
| 21 | +// Package to type mapping |
| 22 | +const packageToType = { |
| 23 | + 'agents-a365-notifications': 'Notifications', |
| 24 | + 'agents-a365-observability': 'Observability', |
| 25 | + 'agents-a365-observability-extensions-openai': 'Observability Extensions', |
| 26 | + 'agents-a365-observability-tokencache': 'Observability Extensions', |
| 27 | + 'agents-a365-runtime': 'Runtime', |
| 28 | + 'agents-a365-tooling': 'Tooling', |
| 29 | + 'agents-a365-tooling-extensions-claude': 'Tooling Extensions', |
| 30 | + 'agents-a365-tooling-extensions-langchain': 'Tooling Extensions', |
| 31 | + 'agents-a365-tooling-extensions-openai': 'Tooling Extensions' |
| 32 | +}; |
| 33 | + |
| 34 | +// Find all package directories matching the pattern |
| 35 | +function findPackages() { |
| 36 | + const packagesDir = path.join(__dirname, 'packages'); |
| 37 | + const packages = []; |
| 38 | + |
| 39 | + const dirs = fs.readdirSync(packagesDir, { withFileTypes: true }); |
| 40 | + |
| 41 | + for (const dir of dirs) { |
| 42 | + if (dir.isDirectory() && dir.name.startsWith('agents-a365-')) { |
| 43 | + const packageJsonPath = path.join(packagesDir, dir.name, 'package.json'); |
| 44 | + if (fs.existsSync(packageJsonPath)) { |
| 45 | + packages.push({ |
| 46 | + name: dir.name, |
| 47 | + path: packageJsonPath |
| 48 | + }); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + return packages; |
| 54 | +} |
| 55 | + |
| 56 | +// Read and parse package.json |
| 57 | +function readPackageJson(packagePath) { |
| 58 | + const content = fs.readFileSync(packagePath, 'utf-8'); |
| 59 | + return JSON.parse(content); |
| 60 | +} |
| 61 | + |
| 62 | +// Extract dependencies related to our packages |
| 63 | +function extractRelevantDependencies(packageJson, relevantPackageNames) { |
| 64 | + const deps = []; |
| 65 | + const allDeps = { |
| 66 | + ...packageJson.dependencies, |
| 67 | + ...packageJson.devDependencies, |
| 68 | + ...packageJson.peerDependencies |
| 69 | + }; |
| 70 | + |
| 71 | + for (const [depName, version] of Object.entries(allDeps || {})) { |
| 72 | + // Check if this dependency is one of our packages |
| 73 | + if (relevantPackageNames.has(depName)) { |
| 74 | + deps.push(depName); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + return deps; |
| 79 | +} |
| 80 | + |
| 81 | +// Generate Mermaid diagram |
| 82 | +function generateMermaidDiagram(packages) { |
| 83 | + let mermaid = '```mermaid\ngraph LR\n'; |
| 84 | + |
| 85 | + // Create a map of package names to directory names |
| 86 | + const packageNameToDir = new Map(); |
| 87 | + for (const pkg of packages) { |
| 88 | + packageNameToDir.set(pkg.packageName, pkg.name); |
| 89 | + } |
| 90 | + |
| 91 | + // Create nodes |
| 92 | + for (const pkg of packages) { |
| 93 | + const nodeId = pkg.name.replace(/-/g, '_'); |
| 94 | + mermaid += ` ${nodeId}[${pkg.name}]\n`; |
| 95 | + } |
| 96 | + |
| 97 | + mermaid += '\n'; |
| 98 | + |
| 99 | + // Create edges (dependencies) |
| 100 | + for (const pkg of packages) { |
| 101 | + const nodeId = pkg.name.replace(/-/g, '_'); |
| 102 | + for (const dep of pkg.dependencies) { |
| 103 | + // Convert package name to directory name |
| 104 | + const depDirName = packageNameToDir.get(dep); |
| 105 | + if (depDirName) { |
| 106 | + const depId = depDirName.replace(/-/g, '_'); |
| 107 | + mermaid += ` ${nodeId} --> ${depId}\n`; |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + mermaid += '\n'; |
| 113 | + |
| 114 | + // Add styling |
| 115 | + for (const pkg of packages) { |
| 116 | + const nodeId = pkg.name.replace(/-/g, '_'); |
| 117 | + const packageType = packageToType[pkg.name]; |
| 118 | + if (packageType) { |
| 119 | + const colors = packageTypeColors[packageType]; |
| 120 | + if (colors) { |
| 121 | + mermaid += ` style ${nodeId} fill:${colors.fill},stroke:${colors.stroke},color:${colors.color}\n`; |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + mermaid += '```\n'; |
| 127 | + |
| 128 | + return mermaid; |
| 129 | +} |
| 130 | + |
| 131 | +// Main function |
| 132 | +function main() { |
| 133 | + console.log('Finding packages...'); |
| 134 | + const packageList = findPackages(); |
| 135 | + console.log(`Found ${packageList.length} packages`); |
| 136 | + |
| 137 | + // Get all package names for filtering dependencies |
| 138 | + const relevantPackageNames = new Set(packageList.map(p => { |
| 139 | + const pkgJson = readPackageJson(p.path); |
| 140 | + return pkgJson.name; |
| 141 | + })); |
| 142 | + |
| 143 | + console.log('Analyzing dependencies...'); |
| 144 | + const packagesWithDeps = packageList.map(pkg => { |
| 145 | + const packageJson = readPackageJson(pkg.path); |
| 146 | + const dependencies = extractRelevantDependencies(packageJson, relevantPackageNames); |
| 147 | + |
| 148 | + console.log(` ${pkg.name}: ${dependencies.length} dependencies`); |
| 149 | + |
| 150 | + return { |
| 151 | + name: pkg.name, |
| 152 | + packageName: packageJson.name, |
| 153 | + dependencies |
| 154 | + }; |
| 155 | + }); |
| 156 | + |
| 157 | + console.log('Generating Mermaid diagram...'); |
| 158 | + const diagram = generateMermaidDiagram(packagesWithDeps); |
| 159 | + |
| 160 | + // Add header and legend |
| 161 | + let markdown = '# Microsoft Agent 365 SDK Node.js Package Dependencies\n\n'; |
| 162 | + markdown += 'This diagram shows the internal dependencies between Microsoft Agent 365 SDK Node.js packages.\n\n'; |
| 163 | + markdown += diagram; |
| 164 | + markdown += '## Package Types\n\n'; |
| 165 | + markdown += '- **Notifications** (Red): Notification and messaging extensions\n'; |
| 166 | + markdown += '- **Observability** (Green): Telemetry and monitoring core\n'; |
| 167 | + markdown += '- **Observability Extensions** (Light Green): Framework-specific observability integrations\n'; |
| 168 | + markdown += '- **Runtime** (Blue): Core runtime components\n'; |
| 169 | + markdown += '- **Tooling** (Orange): Agent tooling SDK core\n'; |
| 170 | + markdown += '- **Tooling Extensions** (Light Orange): Framework-specific tooling integrations\n\n'; |
| 171 | + |
| 172 | + const outputPath = path.join(__dirname, 'DEPENDENCIES.md'); |
| 173 | + fs.writeFileSync(outputPath, markdown, 'utf-8'); |
| 174 | + |
| 175 | + console.log(`\nDiagram generated successfully: ${outputPath}`); |
| 176 | +} |
| 177 | + |
| 178 | +main(); |
0 commit comments