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 type { ReactNode } from 'react'; |
| 2 | import type { Item } from 'fumadocs-core/page-tree'; |
| 3 | import type { ContentStorage } from 'fumadocs-core/source'; |
| 4 | import { z } from 'zod'; |
| 5 | import { DeprecatedApiSidebarLegacyBadge } from '@/components/legacy-badge'; |
| 6 | import { getApiDisplayTitle, isApiPageDeprecated } from '@/lib/api-deprecation'; |
| 7 | import type { ApiPageOperation, OpenApiSchemaPageData } from '@/lib/api-deprecation'; |
| 8 | |
| 9 | // Page data attached by fumadocs-openapi to generated operation pages. MDX |
| 10 | // pages in the same tree lack these members, so the data is parsed once here |
| 11 | // and non-OpenAPI pages simply fail the parse. |
| 12 | const openApiSidebarPageDataSchema = z.object({ |
| 13 | title: z.string(), |
| 14 | getSchema: z.custom<OpenApiSchemaPageData['getSchema']>(value => typeof value === 'function'), |
| 15 | getOpenAPIPageProps: z.custom<() => { operations?: ApiPageOperation[] }>( |
| 16 | value => typeof value === 'function' |
| 17 | ), |
| 18 | }); |
| 19 | |
| 20 | export function getDeprecatedApiSidebarName( |
| 21 | title: string, |
| 22 | pageData: OpenApiSchemaPageData, |
| 23 | operations?: ApiPageOperation[] |
| 24 | ): ReactNode { |
| 25 | if (!isApiPageDeprecated(pageData, operations)) return title; |
| 26 | |
| 27 | return ( |
| 28 | <span className="min-w-0"> |
| 29 | {getApiDisplayTitle(title, true)} <DeprecatedApiSidebarLegacyBadge /> |
| 30 | </span> |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Replaces a deprecated OpenAPI operation's textual title suffix with a |
| 36 | * compact lifecycle badge before fumadocs-openapi appends its method label. |
| 37 | */ |
| 38 | export function transformDeprecatedApiSidebarNode( |
| 39 | node: Item, |
| 40 | filePath: string | undefined, |
| 41 | storage: ContentStorage |
| 42 | ): Item { |
| 43 | if (!filePath) return node; |
| 44 | |
| 45 | const file = storage.read(filePath); |
| 46 | if (!file || file.format !== 'page') return node; |
| 47 | |
| 48 | const pageData = openApiSidebarPageDataSchema.safeParse(file.data); |
| 49 | if (!pageData.success) return node; |
| 50 | |
| 51 | const apiProps = pageData.data.getOpenAPIPageProps(); |
| 52 | return { |
| 53 | ...node, |
| 54 | name: getDeprecatedApiSidebarName(pageData.data.title, pageData.data, apiProps.operations), |
| 55 | }; |
| 56 | } |