import Link from "next/link"; import type { Metadata } from "next"; import { notFound } from "next/navigation"; import type { HTMLAttributes, ReactNode } from "react"; import { MDXRemote } from "next-mdx-remote/rsc"; import rehypePrettyCode from "rehype-pretty-code"; import rehypeSlug from "rehype-slug"; import remarkGfm from "remark-gfm"; import { docs, getAdjacentDocs } from "@/lib/docs"; import { extractHeadings, readArticleByPath } from "@/lib/articles"; import { pageMetadata } from "@/lib/page-metadata"; import { DocsToc } from "@/components/docs-toc"; import { CopyCodeButton } from "@/components/copy-button"; import { HeadingAnchor } from "@/components/heading-anchor"; import { rehypeZeroHighlight } from "@/lib/rehype-zero-highlight"; import { rehypeJsonRender } from "@/lib/rehype-json-render"; import { AgentChat } from "@/components/agent-chat"; import { FlowChart } from "@/components/flow-chart"; type DocsPageParams = { slug?: string[] }; type DocsPageProps = { params: Promise }; export function generateStaticParams(): DocsPageParams[] { return docs.map((doc) => ({ slug: doc.path.replace(/^\//, "").split("/"), })); } export async function generateMetadata({ params }: DocsPageProps): Promise { const { slug } = await params; return pageMetadata((slug ?? []).join("/")); } const rehypePrettyCodeOptions = { theme: { light: "github-light", dark: "github-dark" }, keepBackground: false, }; type HeadingProps = HTMLAttributes & { id?: string; children?: ReactNode; }; function makeHeading(Tag: "h2" | "h3" | "h4") { return function Heading({ id, children, ...rest }: HeadingProps) { return ( {children} ); }; } const mdxComponents = { pre: ({ children, ...props }: HTMLAttributes) => (
{children}
), h2: makeHeading("h2"), h3: makeHeading("h3"), h4: makeHeading("h4"), agentchat: ({ value }: { value?: string }) => { if (!value) return null; try { const spec = JSON.parse(Buffer.from(value, "base64").toString("utf8")); return ; } catch { return null; } }, flowchart: ({ value }: { value?: string }) => { if (!value) return null; try { const spec = JSON.parse(Buffer.from(value, "base64").toString("utf8")); return ; } catch { return null; } }, }; export default async function DocsPage({ params }: DocsPageProps) { const { slug } = await params; const routePath = "/" + (slug ?? []).join("/"); const result = await readArticleByPath(routePath); if (!result) notFound(); const { doc, source } = result; const headings = extractHeadings(source); const { prev, next } = getAdjacentDocs(doc.slug); return ( <>

{doc.section ?? "Documentation"}

{doc.title}

{doc.description}

); }