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, 04:45 UTC
| 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 | /** |
| 21 | * Prepend 'v3' to the slug array since Next.js strips the /v3/ route segment |
| 22 | * but the source has pages registered under v3/... |
| 23 | */ |
| 24 | function toSourceSlug(slug?: string[]): string[] { |
| 25 | return ['v3', ...(slug || [])]; |
| 26 | } |
| 27 | |
| 28 | export default async function Page({ params }: { params: Promise<{ slug?: string[] }> }) { |
| 29 | const { slug } = await params; |
| 30 | const referenceSource = await getReferenceSource(); |
| 31 | const page = referenceSource.getPage(toSourceSlug(slug)); |
| 32 | if (!page) notFound(); |
| 33 | |
| 34 | const openApiData = openApiReferencePageDataSchema.safeParse(page.data); |
| 35 | if (openApiData.success) { |
| 36 | const pageData = openApiData.data; |
| 37 | const apiProps = pageData.getOpenAPIPageProps(); |
| 38 | const detectedVersion = apiProps.operations?.[0]?.path |
| 39 | ? extractVersionFromPath(apiProps.operations[0].path) |
| 40 | : null; |
| 41 | const deprecated = isApiPageDeprecated(pageData, apiProps.operations); |
| 42 | return ( |
| 43 | <DocsPage full footer={{ enabled: false }} tableOfContentPopover={{ enabled: false }}> |
| 44 | <div className="mb-4 flex items-start justify-between gap-4"> |
| 45 | <ApiPageTitle title={pageData.title} version={detectedVersion} deprecated={deprecated} /> |
| 46 | <PageActions path={page.url} variant="inline" /> |
| 47 | </div> |
| 48 | <DocsBody> |
| 49 | <APIPage {...sliceApiPageProps(apiProps)} /> |
| 50 | <EditOnGitHub path={`docs/content/reference/${page.path}`} /> |
| 51 | </DocsBody> |
| 52 | </DocsPage> |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | const mdxData = referenceMdxPageDataSchema.parse(page.data); |
| 57 | const MDX = mdxData.body; |
| 58 | |
| 59 | return ( |
| 60 | <DocsPage |
| 61 | toc={mdxData.toc} |
| 62 | full={mdxData.full} |
| 63 | footer={{ enabled: false }} |
| 64 | tableOfContentPopover={{ enabled: false }} |
| 65 | > |
| 66 | <DocsTitle>{mdxData.title}</DocsTitle> |
| 67 | <PageActions path={page.url} /> |
| 68 | <DocsBody> |
| 69 | <MDX |
| 70 | components={getMDXComponents({ |
| 71 | a: createRelativeLink(referenceSource, page), |
| 72 | })} |
| 73 | /> |
| 74 | <EditOnGitHub path={`docs/content/reference/${page.path}`} /> |
| 75 | </DocsBody> |
| 76 | </DocsPage> |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | export async function generateStaticParams() { |
| 81 | const referenceSource = await getReferenceSource(); |
| 82 | const allParams: { slug: string[] }[] = referenceSource.generateParams(); |
| 83 | // Only return params that start with 'v3', with the prefix stripped |
| 84 | return allParams.filter(p => p.slug[0] === 'v3').map(p => ({ slug: p.slug.slice(1) })); |
| 85 | } |
| 86 | |
| 87 | export async function generateMetadata({ |
| 88 | params, |
| 89 | }: { |
| 90 | params: Promise<{ slug?: string[] }>; |
| 91 | }): Promise<Metadata> { |
| 92 | const { slug } = await params; |
| 93 | const sourceSlug = toSourceSlug(slug); |
| 94 | |
| 95 | if (!slug || slug.length === 0) { |
| 96 | const ogImage = getOgImageUrl( |
| 97 | 'reference', |
| 98 | [], |
| 99 | 'API Reference (v3)', |
| 100 | 'REST API reference for Composio v3', |
| 101 | { version: 'v3' } |
| 102 | ); |
| 103 | return { |
| 104 | title: 'API Reference (v3)', |
| 105 | description: 'REST API reference for Composio v3', |
| 106 | alternates: markdownAlternates('/reference/v3'), |
| 107 | openGraph: { images: [ogImage] }, |
| 108 | twitter: { card: 'summary_large_image', images: [ogImage] }, |
| 109 | }; |
| 110 | } |
| 111 | |
| 112 | const referenceSource = await getReferenceSource(); |
| 113 | const page = referenceSource.getPage(sourceSlug); |
| 114 | if (!page) notFound(); |
| 115 | |
| 116 | const description = page.data.description || page.data.title; |
| 117 | // The card already shows the title; only pass a description when there is a real one. |
| 118 | const ogImage = getOgImageUrl('reference', page.slugs, page.data.title, page.data.description, { |
| 119 | version: 'v3', |
| 120 | }); |
| 121 | |
| 122 | return { |
| 123 | title: page.data.title, |
| 124 | description, |
| 125 | alternates: markdownAlternates(page.url), |
| 126 | openGraph: { images: [ogImage] }, |
| 127 | twitter: { card: 'summary_large_image', images: [ogImage] }, |
| 128 | }; |
| 129 | } |