Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 03:37 UTC
| 1 | import { fileURLToPath } from 'node:url'; |
| 2 | import { checkApiSnippets, loadApiSpecs } from '../lib/api-snippets'; |
| 3 | import { listCodeExampleFiles } from '../lib/code-examples'; |
| 4 | |
| 5 | const USAGE = 'Usage: bun scripts/check-api-snippets.ts [--json]'; |
| 6 | const args = process.argv.slice(2); |
| 7 | const unknown = args.filter((arg) => arg !== '--json'); |
| 8 | if (unknown.length) { |
| 9 | console.error(`Unknown argument(s): ${unknown.join(' ')}\n${USAGE}`); |
| 10 | process.exit(2); |
| 11 | } |
| 12 | |
| 13 | const docsRoot = fileURLToPath(new URL('..', import.meta.url)); |
| 14 | const files = listCodeExampleFiles(docsRoot); |
| 15 | const violations = checkApiSnippets(files, loadApiSpecs(docsRoot)); |
| 16 | const counts: Record<string, number> = {}; |
| 17 | for (const violation of violations) counts[violation.rule] = (counts[violation.rule] ?? 0) + 1; |
| 18 | const sortedCounts = Object.fromEntries(Object.entries(counts).sort(([a], [b]) => a.localeCompare(b))); |
| 19 | |
| 20 | if (args.includes('--json')) { |
| 21 | console.log(JSON.stringify({ files: files.length, violations, counts: sortedCounts }, null, 2)); |
| 22 | } else if (violations.length) { |
| 23 | for (const { path, line, rule, message } of violations) console.log(`${path}:${line} ${rule} ${message}`); |
| 24 | const fileCount = new Set(violations.map((violation) => violation.path)).size; |
| 25 | console.log(`\n${violations.length} API snippet violation(s) in ${fileCount} of ${files.length} file(s):`); |
| 26 | for (const [rule, count] of Object.entries(sortedCounts)) console.log(` ${rule}: ${count}`); |
| 27 | } else { |
| 28 | console.log(`No API snippet violations in ${files.length} file(s).`); |
| 29 | } |
| 30 | |
| 31 | process.exit(violations.length ? 1 : 0); |