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 { useState, useMemo, useDeferredValue, useEffect, useRef } from 'react'; |
| 4 | import Link from 'next/link'; |
| 5 | import { Search, Copy, Check } from 'lucide-react'; |
| 6 | |
| 7 | interface ManagedAuthToolkit { |
| 8 | slug: string; |
| 9 | name: string; |
| 10 | logo: string | null; |
| 11 | authSchemes: string[]; |
| 12 | composioManagedAuthSchemes?: string[]; |
| 13 | toolCount: number; |
| 14 | triggerCount: number; |
| 15 | } |
| 16 | |
| 17 | function CopyButton({ toolkits }: { toolkits: ManagedAuthToolkit[] }) { |
| 18 | const [copied, setCopied] = useState(false); |
| 19 | |
| 20 | const handleCopy = () => { |
| 21 | const text = toolkits.map((t) => t.slug).join(', '); |
| 22 | navigator.clipboard.writeText(text); |
| 23 | setCopied(true); |
| 24 | setTimeout(() => setCopied(false), 2000); |
| 25 | }; |
| 26 | |
| 27 | return ( |
| 28 | <button |
| 29 | onClick={handleCopy} |
| 30 | className="inline-flex items-center gap-1 text-xs text-fd-muted-foreground transition-colors hover:text-fd-foreground" |
| 31 | > |
| 32 | {copied ? <Check className="h-3 w-3 text-green-500" /> : <Copy className="h-3 w-3" />} |
| 33 | {copied ? 'Copied!' : 'Copy slugs'} |
| 34 | </button> |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | function CopySlugButton({ slug }: { slug: string }) { |
| 39 | const [copied, setCopied] = useState(false); |
| 40 | |
| 41 | const handleCopy = (e: React.MouseEvent) => { |
| 42 | e.preventDefault(); |
| 43 | navigator.clipboard.writeText(slug.toUpperCase()); |
| 44 | setCopied(true); |
| 45 | setTimeout(() => setCopied(false), 2000); |
| 46 | }; |
| 47 | |
| 48 | return ( |
| 49 | <button |
| 50 | onClick={handleCopy} |
| 51 | aria-label={`Copy ${slug.toUpperCase()} to clipboard`} |
| 52 | className="inline-flex items-center gap-1 rounded bg-fd-muted px-1.5 py-0.5 font-mono text-xs text-fd-muted-foreground transition-colors hover:text-fd-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500" |
| 53 | > |
| 54 | <span className="max-w-[120px] truncate sm:max-w-none">{slug.toUpperCase()}</span> |
| 55 | {copied ? <Check className="h-3 w-3 text-green-500" aria-hidden="true" /> : <Copy className="h-3 w-3" aria-hidden="true" />} |
| 56 | </button> |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | function ToolkitIcon({ toolkit }: { toolkit: ManagedAuthToolkit }) { |
| 61 | const [imgFailed, setImgFailed] = useState(false); |
| 62 | const fallback = toolkit.name.trim().charAt(0).toUpperCase(); |
| 63 | |
| 64 | return ( |
| 65 | <div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-fd-border/50 bg-fd-background text-sm font-medium text-fd-muted-foreground sm:h-10 sm:w-10"> |
| 66 | {toolkit.logo && !imgFailed ? ( |
| 67 | <img |
| 68 | src={toolkit.logo} |
| 69 | alt="" |
| 70 | loading="lazy" |
| 71 | decoding="async" |
| 72 | className="h-[65%] w-[65%] object-contain" |
| 73 | onError={() => setImgFailed(true)} |
| 74 | /> |
| 75 | ) : ( |
| 76 | fallback |
| 77 | )} |
| 78 | </div> |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | function ToolkitRow({ toolkit }: { toolkit: ManagedAuthToolkit }) { |
| 83 | return ( |
| 84 | <Link |
| 85 | href={`/toolkits/${toolkit.slug}`} |
| 86 | className="group flex flex-col gap-2 px-2 py-3 transition-colors hover:bg-fd-accent/30 sm:flex-row sm:items-center sm:justify-between sm:px-0 sm:py-2.5" |
| 87 | > |
| 88 | <div className="flex items-center gap-3"> |
| 89 | <ToolkitIcon toolkit={toolkit} /> |
| 90 | <div className="flex min-w-0 flex-1 flex-col gap-1 sm:flex-row sm:items-center sm:gap-3"> |
| 91 | <span className="truncate text-sm font-medium text-fd-foreground">{toolkit.name.trim()}</span> |
| 92 | <CopySlugButton slug={toolkit.slug} /> |
| 93 | </div> |
| 94 | </div> |
| 95 | </Link> |
| 96 | ); |
| 97 | } |
| 98 | |
| 99 | export function ManagedAuthList() { |
| 100 | const [data, setData] = useState<ManagedAuthToolkit[] | null>(null); |
| 101 | const [tab, setTab] = useState<'managed' | 'unmanaged'>('managed'); |
| 102 | const [search, setSearch] = useState(''); |
| 103 | const deferredSearch = useDeferredValue(search); |
| 104 | |
| 105 | useEffect(() => { |
| 106 | fetch('/data/toolkits.json') |
| 107 | .then((res) => res.json()) |
| 108 | .then((all: ManagedAuthToolkit[]) => { |
| 109 | setData(all.filter((t) => t.authSchemes?.some((s) => s.toUpperCase().includes('OAUTH')))); |
| 110 | }); |
| 111 | }, []); |
| 112 | |
| 113 | const filtered = useMemo(() => { |
| 114 | if (!data) return []; |
| 115 | const s = deferredSearch.toLowerCase(); |
| 116 | const list = s |
| 117 | ? data.filter((t) => t.name.toLowerCase().includes(s) || t.slug.toLowerCase().includes(s)) |
| 118 | : data; |
| 119 | return [...list].sort((a, b) => a.name.trim().localeCompare(b.name.trim())); |
| 120 | }, [data, deferredSearch]); |
| 121 | |
| 122 | const managed = useMemo( |
| 123 | () => filtered.filter((t) => t.composioManagedAuthSchemes && t.composioManagedAuthSchemes.length > 0), |
| 124 | [filtered] |
| 125 | ); |
| 126 | const notManaged = useMemo( |
| 127 | () => filtered.filter((t) => !t.composioManagedAuthSchemes || t.composioManagedAuthSchemes.length === 0), |
| 128 | [filtered] |
| 129 | ); |
| 130 | |
| 131 | // Auto-switch tab when search leaves current tab empty but other has results |
| 132 | const prevSearch = useRef(deferredSearch); |
| 133 | useEffect(() => { |
| 134 | if (deferredSearch !== prevSearch.current) { |
| 135 | prevSearch.current = deferredSearch; |
| 136 | if (tab === 'managed' && managed.length === 0 && notManaged.length > 0) { |
| 137 | setTab('unmanaged'); |
| 138 | } else if (tab === 'unmanaged' && notManaged.length === 0 && managed.length > 0) { |
| 139 | setTab('managed'); |
| 140 | } |
| 141 | } |
| 142 | }, [deferredSearch, tab, managed.length, notManaged.length]); |
| 143 | |
| 144 | const activeList = tab === 'managed' ? managed : notManaged; |
| 145 | |
| 146 | if (!data) { |
| 147 | return <p className="py-8 text-center text-sm text-fd-muted-foreground">Loading toolkits...</p>; |
| 148 | } |
| 149 | |
| 150 | return ( |
| 151 | <div className="space-y-4"> |
| 152 | {/* Search */} |
| 153 | <label htmlFor="managed-auth-toolkit-search" className="sr-only"> |
| 154 | Search toolkits by managed OAuth availability |
| 155 | </label> |
| 156 | <div className="relative"> |
| 157 | <Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-fd-muted-foreground" aria-hidden="true" /> |
| 158 | <input |
| 159 | id="managed-auth-toolkit-search" |
| 160 | type="text" |
| 161 | placeholder="Search toolkits..." |
| 162 | autoComplete="off" |
| 163 | value={search} |
| 164 | onChange={(e) => setSearch(e.target.value)} |
| 165 | className="h-10 w-full rounded-lg border border-fd-border bg-fd-background pl-10 pr-4 text-sm text-fd-foreground placeholder:text-fd-muted-foreground focus:outline-none focus-visible:border-blue-500/50 focus-visible:ring-2 focus-visible:ring-blue-500/20" |
| 166 | /> |
| 167 | </div> |
| 168 | |
| 169 | {/* Tabs */} |
| 170 | <div className="flex items-center gap-1 border-b border-fd-border"> |
| 171 | <button |
| 172 | onClick={() => setTab('managed')} |
| 173 | className={`flex items-center gap-2 border-b-2 px-3 py-2 text-sm font-medium transition-colors ${ |
| 174 | tab === 'managed' |
| 175 | ? 'border-green-500 text-fd-foreground' |
| 176 | : 'border-transparent text-fd-muted-foreground hover:text-fd-foreground' |
| 177 | }`} |
| 178 | > |
| 179 | <span className="inline-block h-2 w-2 rounded-full bg-green-500" /> |
| 180 | Composio-managed OAuth available |
| 181 | <span className="rounded-full bg-fd-muted px-1.5 py-0.5 text-xs">{managed.length}</span> |
| 182 | </button> |
| 183 | <button |
| 184 | onClick={() => setTab('unmanaged')} |
| 185 | className={`flex items-center gap-2 border-b-2 px-3 py-2 text-sm font-medium transition-colors ${ |
| 186 | tab === 'unmanaged' |
| 187 | ? 'border-fd-muted-foreground text-fd-foreground' |
| 188 | : 'border-transparent text-fd-muted-foreground hover:text-fd-foreground' |
| 189 | }`} |
| 190 | > |
| 191 | <span className="inline-block h-2 w-2 rounded-full bg-fd-muted-foreground/60" /> |
| 192 | Bring your own OAuth app |
| 193 | <span className="rounded-full bg-fd-muted px-1.5 py-0.5 text-xs">{notManaged.length}</span> |
| 194 | </button> |
| 195 | </div> |
| 196 | |
| 197 | {/* Copy slugs — separate row, aligned with list content */} |
| 198 | <div className="flex justify-end"> |
| 199 | <CopyButton toolkits={activeList} /> |
| 200 | </div> |
| 201 | |
| 202 | {/* List */} |
| 203 | {activeList.length > 0 ? ( |
| 204 | <div className="divide-y divide-fd-border"> |
| 205 | {activeList.map((t) => ( |
| 206 | <ToolkitRow key={t.slug} toolkit={t} /> |
| 207 | ))} |
| 208 | </div> |
| 209 | ) : ( |
| 210 | <p className="py-8 text-center text-sm text-fd-muted-foreground">No toolkits found.</p> |
| 211 | )} |
| 212 | </div> |
| 213 | ); |
| 214 | } |