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 { markdownAlternates } from '@/lib/markdown-alternates'; |
| 2 | import { getReferenceSource, getOgImageUrl } from '@/lib/source'; |
| 3 | import { APIPage } from '@/components/api-page'; |
| 4 | import { DocsBody, DocsPage, DocsTitle } from 'fumadocs-ui/layouts/docs/page'; |
| 5 | import { notFound } from 'next/navigation'; |
| 6 | import { getMDXComponents } from '@/mdx-components'; |
| 7 | import type { Metadata } from 'next'; |
| 8 | import { createRelativeLink } from 'fumadocs-ui/mdx'; |
| 9 | import { PageActions } from '@/components/page-actions'; |
| 10 | import { EditOnGitHub } from '@/components/edit-on-github'; |
| 11 | import { extractVersionFromPath } from '@/components/version-badge'; |
| 12 | import { ApiPageTitle } from '@/components/api-page-title'; |
| 13 | import { isApiPageDeprecated } from '@/lib/api-deprecation'; |
| 14 | import { sliceApiPageProps } from '@/lib/openapi-slice'; |
| 15 | import { |
| 16 | openApiReferencePageDataSchema, |
| 17 | referenceMdxPageDataSchema, |
| 18 | } from '@/lib/reference-page-data'; |
| 19 | |
| 20 | export default async function Page({ params }: { params: Promise<{ slug?: string[] }> }) { |
| 21 | const { slug } = await params; |
| 22 | const referenceSource = await getReferenceSource(); |
| 23 | const page = referenceSource.getPage(slug); |
| 24 | if (!page) notFound(); |
| 25 | |
| 26 | const openApiData = openApiReferencePageDataSchema.safeParse(page.data); |
| 27 | if (openApiData.success) { |
| 28 | const pageData = openApiData.data; |
| 29 | const apiProps = pageData.getOpenAPIPageProps(); |
| 30 | const detectedVersion = apiProps.operations?.[0]?.path |
| 31 | ? extractVersionFromPath(apiProps.operations[0].path) |
| 32 | : null; |
| 33 | const deprecated = isApiPageDeprecated(pageData, apiProps.operations); |
| 34 | return ( |
| 35 | <DocsPage full footer={{ enabled: false }} tableOfContentPopover={{ enabled: false }}> |
| 36 | <div className="mb-4 flex items-start justify-between gap-4"> |
| 37 | <ApiPageTitle title={pageData.title} version={detectedVersion} deprecated={deprecated} /> |
| 38 | <PageActions path={page.url} variant="inline" /> |
| 39 | </div> |
| 40 | <DocsBody> |
| 41 | <APIPage {...sliceApiPageProps(apiProps)} /> |
| 42 | <EditOnGitHub path={`docs/content/reference/${page.path}`} /> |
| 43 | </DocsBody> |
| 44 | </DocsPage> |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | const mdxData = referenceMdxPageDataSchema.parse(page.data); |
| 49 | const MDX = mdxData.body; |
| 50 | |
| 51 | return ( |
| 52 | <DocsPage |
| 53 | toc={mdxData.toc} |
| 54 | full={mdxData.full} |
| 55 | footer={{ enabled: false }} |
| 56 | tableOfContentPopover={{ enabled: false }} |
| 57 | > |
| 58 | <DocsTitle>{mdxData.title}</DocsTitle> |
| 59 | <PageActions path={page.url} /> |
| 60 | <DocsBody> |
| 61 | <MDX |
| 62 | components={getMDXComponents({ |
| 63 | a: createRelativeLink(referenceSource, page), |
| 64 | })} |
| 65 | /> |
| 66 | <EditOnGitHub path={`docs/content/reference/${page.path}`} /> |
| 67 | </DocsBody> |
| 68 | </DocsPage> |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | export async function generateStaticParams() { |
| 73 | const referenceSource = await getReferenceSource(); |
| 74 | const allParams: { slug: string[] }[] = referenceSource.generateParams(); |
| 75 | // Exclude v3 pages — those are handled by the /reference/v3/ route |
| 76 | return allParams.filter(p => p.slug[0] !== 'v3'); |
| 77 | } |
| 78 | |
| 79 | export async function generateMetadata({ |
| 80 | params, |
| 81 | }: { |
| 82 | params: Promise<{ slug?: string[] }>; |
| 83 | }): Promise<Metadata> { |
| 84 | const { slug } = await params; |
| 85 | |
| 86 | if (!slug || slug.length === 0) { |
| 87 | const ogImage = getOgImageUrl( |
| 88 | 'reference', |
| 89 | [], |
| 90 | 'API Reference', |
| 91 | 'REST API and SDK reference for Composio', |
| 92 | { version: 'v3.1' } |
| 93 | ); |
| 94 | return { |
| 95 | title: 'API Reference', |
| 96 | description: 'REST API and SDK reference for Composio', |
| 97 | alternates: markdownAlternates('/reference'), |
| 98 | openGraph: { images: [ogImage] }, |
| 99 | twitter: { card: 'summary_large_image', images: [ogImage] }, |
| 100 | }; |
| 101 | } |
| 102 | |
| 103 | const referenceSource = await getReferenceSource(); |
| 104 | const page = referenceSource.getPage(slug); |
| 105 | if (!page) notFound(); |
| 106 | |
| 107 | const description = page.data.description || page.data.title; |
| 108 | // The card already shows the title; only pass a description when there is a real one. |
| 109 | const ogImage = getOgImageUrl('reference', page.slugs, page.data.title, page.data.description, { |
| 110 | version: 'v3.1', |
| 111 | }); |
| 112 | |
| 113 | return { |
| 114 | title: page.data.title, |
| 115 | description, |
| 116 | alternates: markdownAlternates(page.url), |
| 117 | openGraph: { images: [ogImage] }, |
| 118 | twitter: { card: 'summary_large_image', images: [ogImage] }, |
| 119 | }; |
| 120 | } |