Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; |
| 2 | import { dirname, join, resolve } from 'node:path'; |
| 3 | import { |
| 4 | source, getReferenceSource, examplesSource, toolkitsSource, |
| 5 | changelogEntries, dateToChangelogUrl, |
| 6 | } from '../lib/source'; |
| 7 | import { |
| 8 | buildContentFreshness, getExplicitLastUpdated, type FreshnessPage, |
| 9 | } from '../lib/content-freshness-build'; |
| 10 | |
| 11 | const root = process.cwd(); |
| 12 | const pages = new Map<string, FreshnessPage>(); |
| 13 | const explicitSources: Record<string, string> = {}; |
| 14 | |
| 15 | function add(pathname: string, sources: string[]) { |
| 16 | const current = pages.get(pathname); |
| 17 | pages.set(pathname, { pathname, sources: [...new Set([...(current?.sources ?? []), ...sources])] }); |
| 18 | } |
| 19 | |
| 20 | function authored(pathname: string, absolutePath?: string) { |
| 21 | if (!absolutePath || !existsSync(absolutePath)) return; |
| 22 | const raw = readFileSync(absolutePath, 'utf8'); |
| 23 | // Generated files can change when an unrelated catalog entry changes. |
| 24 | if (raw.includes('Auto-generated')) return; |
| 25 | const explicit = getExplicitLastUpdated(raw); |
| 26 | if (explicit !== undefined) explicitSources[resolve(absolutePath)] = explicit; |
| 27 | add(pathname, [absolutePath]); |
| 28 | } |
| 29 | |
| 30 | for (const collection of [source, examplesSource, toolkitsSource]) { |
| 31 | for (const page of collection.getPages()) authored(page.url, page.absolutePath); |
| 32 | } |
| 33 | |
| 34 | const reference = await getReferenceSource(); |
| 35 | for (const page of reference.getPages()) { |
| 36 | authored(page.url, page.absolutePath); |
| 37 | } |
| 38 | |
| 39 | for (const entry of changelogEntries) { |
| 40 | const file = join(root, 'content/changelog', entry.info.path); |
| 41 | const filenameDate = entry.info.path.match(/^(\d{2})-(\d{2})-(\d{2})(?:-|\.)/); |
| 42 | const date = /^\d{4}-\d{2}-\d{2}$/.test(entry.date) ? entry.date |
| 43 | : filenameDate ? `20${filenameDate[3]}-${filenameDate[1]}-${filenameDate[2]}` : null; |
| 44 | if (date) authored(dateToChangelogUrl(date), file); |
| 45 | } |
| 46 | |
| 47 | // Browse pages include data outside their authored MDX. Omit freshness until |
| 48 | // changes can be attributed to the page instead of an entire shared corpus. |
| 49 | for (const pathname of ['/docs', '/examples', '/toolkits', '/toolkits/managed-auth', |
| 50 | '/reference', '/reference/v3']) { |
| 51 | pages.delete(pathname); |
| 52 | } |
| 53 | |
| 54 | const manifest = buildContentFreshness(root, [...pages.values()], explicitSources); |
| 55 | const output = join(root, '.generated/content-freshness.json'); |
| 56 | mkdirSync(dirname(output), { recursive: true }); |
| 57 | writeFileSync(output, `${JSON.stringify(manifest, null, 2)}\n`); |
| 58 | console.log(`Persisted trustworthy freshness for ${Object.keys(manifest.pages).length} pages.`); |