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 | 'use client'; |
| 2 | |
| 3 | import { ArrowUpRight, Key } from 'lucide-react'; |
| 4 | import Link from 'next/link'; |
| 5 | import { TypeTable } from 'fumadocs-ui/components/type-table'; |
| 6 | import { Accordion, Accordions } from '@/mdx-components'; |
| 7 | import type { AuthConfigDetail, AuthConfigField } from '@/types/toolkit'; |
| 8 | |
| 9 | interface AuthDetailsSectionProps { |
| 10 | authConfigDetails: AuthConfigDetail[]; |
| 11 | authSchemes?: string[]; |
| 12 | composioManagedAuthSchemes?: string[]; |
| 13 | } |
| 14 | |
| 15 | function formatTypeName(mode: string): string { |
| 16 | const modeMap: Record<string, string> = { |
| 17 | oauth2: 'OAuth2', |
| 18 | oauth1: 'OAuth1', |
| 19 | api_key: 'API Key', |
| 20 | basic_auth: 'Basic Auth', |
| 21 | bearer_token: 'Bearer Token', |
| 22 | no_auth: 'No Auth', |
| 23 | }; |
| 24 | return modeMap[mode.toLowerCase()] || mode; |
| 25 | } |
| 26 | |
| 27 | function fieldsToTypeTable(fields: AuthConfigField[]): Record<string, { |
| 28 | type: string; |
| 29 | description?: string; |
| 30 | default?: string; |
| 31 | required?: boolean; |
| 32 | }> { |
| 33 | const result: Record<string, { |
| 34 | type: string; |
| 35 | description?: string; |
| 36 | default?: string; |
| 37 | required?: boolean; |
| 38 | }> = {}; |
| 39 | |
| 40 | for (const field of fields) { |
| 41 | result[field.name] = { |
| 42 | type: field.type || 'string', |
| 43 | description: field.description || undefined, |
| 44 | default: field.default || undefined, |
| 45 | required: field.required, |
| 46 | }; |
| 47 | } |
| 48 | |
| 49 | return result; |
| 50 | } |
| 51 | |
| 52 | function getAllFields(detail: AuthConfigDetail): AuthConfigField[] { |
| 53 | if (!detail?.fields) return []; |
| 54 | return [ |
| 55 | ...(detail.fields.auth_config_creation?.required || []), |
| 56 | ...(detail.fields.auth_config_creation?.optional || []), |
| 57 | ...(detail.fields.connected_account_initiation?.required || []), |
| 58 | ...(detail.fields.connected_account_initiation?.optional || []), |
| 59 | ]; |
| 60 | } |
| 61 | |
| 62 | export function AuthDetailsSection({ authConfigDetails, authSchemes, composioManagedAuthSchemes }: AuthDetailsSectionProps) { |
| 63 | if (!authConfigDetails || authConfigDetails.length === 0) { |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | // Filter out auth modes with no fields in either section |
| 68 | const validDetails = authConfigDetails.filter((detail) => { |
| 69 | return detail && getAllFields(detail).length > 0; |
| 70 | }); |
| 71 | |
| 72 | if (validDetails.length === 0) { |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | const hasOAuth = authSchemes?.some((s) => s.toUpperCase().includes('OAUTH')) ?? false; |
| 77 | |
| 78 | return ( |
| 79 | <div className="space-y-3"> |
| 80 | <h2 className="flex items-center gap-2 text-base font-semibold text-fd-foreground"> |
| 81 | <Key className="h-4 w-4" /> |
| 82 | Authentication Details |
| 83 | {hasOAuth && ( |
| 84 | composioManagedAuthSchemes && composioManagedAuthSchemes.length > 0 ? ( |
| 85 | <Link |
| 86 | href="/toolkits/managed-auth" |
| 87 | className="inline-flex items-center gap-1.5 border border-fd-border bg-fd-card px-2 py-0.5 font-mono text-[10px] uppercase tracking-[0.06em] text-fd-foreground transition-colors hover:border-fd-foreground/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring" |
| 88 | > |
| 89 | <span className="size-1.5 rounded-full bg-green-500" aria-hidden="true" /> |
| 90 | Composio-managed OAuth available |
| 91 | <ArrowUpRight className="size-3" aria-hidden="true" /> |
| 92 | </Link> |
| 93 | ) : ( |
| 94 | <span className="rounded bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-600 dark:text-amber-400"> |
| 95 | Composio-managed OAuth not available |
| 96 | </span> |
| 97 | ) |
| 98 | )} |
| 99 | </h2> |
| 100 | <Accordions type="single"> |
| 101 | {validDetails.map((detail) => { |
| 102 | const fields = getAllFields(detail); |
| 103 | return ( |
| 104 | <Accordion key={detail.mode} title={formatTypeName(detail.mode)}> |
| 105 | <TypeTable type={fieldsToTypeTable(fields)} /> |
| 106 | </Accordion> |
| 107 | ); |
| 108 | })} |
| 109 | </Accordions> |
| 110 | </div> |
| 111 | ); |
| 112 | } |