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 { InstantBadge } from './instant-badge'; |
| 4 | import { InstantBolt } from './instant-bolt'; |
| 5 | import { filterToolkits, instantToolkitSlugsSchema, withInstantEligibility } from '@/lib/instant-toolkit-filter'; |
| 6 | |
| 7 | import { useState, useMemo, useDeferredValue, useEffect } from 'react'; |
| 8 | import Link from 'next/link'; |
| 9 | import { Search, Wrench, Zap, Copy, Check, ExternalLink, Grip, ShieldCheck } from 'lucide-react'; |
| 10 | import { Card, Cards } from 'fumadocs-ui/components/card'; |
| 11 | import toolkitsData from '@/public/data/toolkits-list.json'; |
| 12 | import type { ToolkitSummary } from '@/types/toolkit'; |
| 13 | import { PageActions } from '@/components/page-actions'; |
| 14 | |
| 15 | const snapshot: ToolkitSummary[] = toolkitsData; |
| 16 | |
| 17 | // Popular toolkit slugs (shown at top when no filters) |
| 18 | const POPULAR_SLUGS = [ |
| 19 | 'github', |
| 20 | 'gmail', |
| 21 | 'slack', |
| 22 | 'notion', |
| 23 | 'googlesheets', |
| 24 | 'shopify', |
| 25 | 'googledrive', |
| 26 | 'supabase', |
| 27 | 'hubspot', |
| 28 | ]; |
| 29 | |
| 30 | function ToolkitIcon({ toolkit, lazy = true }: { toolkit: ToolkitSummary; lazy?: boolean }) { |
| 31 | const [imgFailed, setImgFailed] = useState(false); |
| 32 | const fallback = toolkit.name.trim().charAt(0).toUpperCase(); |
| 33 | |
| 34 | return ( |
| 35 | <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"> |
| 36 | {toolkit.logo && !imgFailed ? ( |
| 37 | <img |
| 38 | src={toolkit.logo} |
| 39 | alt="" |
| 40 | loading={lazy ? 'lazy' : 'eager'} |
| 41 | decoding="async" |
| 42 | className="h-[65%] w-[65%] object-contain" |
| 43 | onError={() => setImgFailed(true)} |
| 44 | /> |
| 45 | ) : ( |
| 46 | fallback |
| 47 | )} |
| 48 | </div> |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | function CopySlugButton({ slug }: { slug: string }) { |
| 53 | const [copied, setCopied] = useState(false); |
| 54 | |
| 55 | const handleCopy = (e: React.MouseEvent) => { |
| 56 | e.preventDefault(); |
| 57 | navigator.clipboard.writeText(slug.toUpperCase()); |
| 58 | setCopied(true); |
| 59 | setTimeout(() => setCopied(false), 2000); |
| 60 | }; |
| 61 | |
| 62 | return ( |
| 63 | <button |
| 64 | onClick={handleCopy} |
| 65 | aria-label={`Copy ${slug.toUpperCase()} to clipboard`} |
| 66 | 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" |
| 67 | > |
| 68 | <span className="max-w-[120px] truncate sm:max-w-none">{slug.toUpperCase()}</span> |
| 69 | {copied ? <Check className="h-3 w-3 text-green-500" aria-hidden="true" /> : <Copy className="h-3 w-3" aria-hidden="true" />} |
| 70 | </button> |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | function ToolkitRow({ toolkit, lazy = true }: { toolkit: ToolkitSummary; lazy?: boolean }) { |
| 75 | return ( |
| 76 | <Link |
| 77 | href={`/toolkits/${toolkit.slug}`} |
| 78 | 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" |
| 79 | > |
| 80 | {/* Left side: Icon, Name, Slug */} |
| 81 | <div className="flex items-center gap-3"> |
| 82 | <ToolkitIcon toolkit={toolkit} lazy={lazy} /> |
| 83 | <div className="flex min-w-0 flex-1 flex-col gap-1 sm:flex-row sm:items-center sm:gap-3"> |
| 84 | <span className="truncate text-sm font-medium text-fd-foreground">{toolkit.name.trim()}</span> |
| 85 | {toolkit.instant?.supported === true && <InstantBadge />} |
| 86 | <CopySlugButton slug={toolkit.slug} /> |
| 87 | </div> |
| 88 | </div> |
| 89 | {/* Right side: Counts */} |
| 90 | <div className="flex items-center gap-3 pl-12 text-xs text-fd-muted-foreground sm:pl-0"> |
| 91 | <span className="flex items-center gap-1"> |
| 92 | <Wrench className="h-3.5 w-3.5" aria-hidden="true" /> |
| 93 | {toolkit.toolCount} |
| 94 | </span> |
| 95 | <span className="flex items-center gap-1"> |
| 96 | <Zap className="h-3.5 w-3.5" aria-hidden="true" /> |
| 97 | {toolkit.triggerCount} |
| 98 | </span> |
| 99 | </div> |
| 100 | </Link> |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | export function ToolkitsLanding() { |
| 105 | const [search, setSearch] = useState(''); |
| 106 | const [instantOnly, setInstantOnly] = useState(false); |
| 107 | const [eligibility, setEligibility] = useState<string[] | null>(null); |
| 108 | const [eligibilityFailed, setEligibilityFailed] = useState(false); |
| 109 | const [retry, setRetry] = useState(0); |
| 110 | useEffect(() => { |
| 111 | const controller = new AbortController(); |
| 112 | fetch('/api/toolkits/instant', { signal: controller.signal }) |
| 113 | .then(async response => { |
| 114 | if (!response.ok) throw new Error('Availability unavailable'); |
| 115 | return instantToolkitSlugsSchema.parse(await response.json()); |
| 116 | }) |
| 117 | .then(data => setEligibility(data.slugs)) |
| 118 | .catch(() => { if (!controller.signal.aborted) setEligibilityFailed(true); }); |
| 119 | return () => controller.abort(); |
| 120 | }, [retry]); |
| 121 | const toolkits = useMemo(() => eligibility === null ? snapshot : withInstantEligibility(snapshot, eligibility), [eligibility]); |
| 122 | const instantUnavailable = instantOnly && eligibility === null; |
| 123 | const clearFilters = () => { setSearch(''); setInstantOnly(false); }; |
| 124 | const deferredSearch = useDeferredValue(search); |
| 125 | |
| 126 | // Get popular toolkits |
| 127 | const popularToolkits = useMemo(() => { |
| 128 | return POPULAR_SLUGS |
| 129 | .map((slug) => toolkits.find((t) => t.slug === slug)) |
| 130 | .filter((t): t is ToolkitSummary => t !== undefined); |
| 131 | }, [toolkits]); |
| 132 | |
| 133 | const filteredToolkits = useMemo(() => { |
| 134 | return filterToolkits(toolkits, deferredSearch, instantOnly); |
| 135 | }, [toolkits, deferredSearch, instantOnly]); |
| 136 | |
| 137 | // Group by first letter (numbers at end) |
| 138 | const groupedToolkits = useMemo(() => { |
| 139 | const groups: Record<string, ToolkitSummary[]> = {}; |
| 140 | |
| 141 | // First sort all toolkits alphabetically (trim to handle leading spaces) |
| 142 | const sorted = [...filteredToolkits].sort((a, b) => |
| 143 | (a.name?.trim() || '').localeCompare(b.name?.trim() || '') |
| 144 | ); |
| 145 | |
| 146 | sorted.forEach((toolkit) => { |
| 147 | const firstChar = (toolkit.name?.trim() || '#').charAt(0).toUpperCase(); |
| 148 | // Group all numbers under '#' |
| 149 | const letter = /[0-9]/.test(firstChar) ? '#' : firstChar; |
| 150 | if (!groups[letter]) { |
| 151 | groups[letter] = []; |
| 152 | } |
| 153 | groups[letter].push(toolkit); |
| 154 | }); |
| 155 | |
| 156 | // Sort groups with letters first (A-Z), then # (numbers) at end |
| 157 | return Object.entries(groups).sort(([a], [b]) => { |
| 158 | if (a === '#') return 1; |
| 159 | if (b === '#') return -1; |
| 160 | return a.localeCompare(b); |
| 161 | }); |
| 162 | }, [filteredToolkits]); |
| 163 | |
| 164 | return ( |
| 165 | <div className="space-y-5 sm:space-y-8"> |
| 166 | {/* Header */} |
| 167 | <div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between"> |
| 168 | <div> |
| 169 | <h1 className="text-2xl font-bold text-fd-foreground sm:text-3xl">Toolkits</h1> |
| 170 | <p className="mt-1.5 text-sm text-fd-muted-foreground sm:mt-2 sm:text-base"> |
| 171 | Browse {toolkits.length} toolkits supported by Composio |
| 172 | </p> |
| 173 | </div> |
| 174 | <div className="flex flex-wrap items-center gap-2"> |
| 175 | <PageActions path="/toolkits" variant="inline" /> |
| 176 | <a |
| 177 | href="https://dashboard.composio.dev/~/project/playground?utm_source=docs&utm_medium=toolkits&utm_campaign=playground" |
| 178 | target="_blank" |
| 179 | rel="noopener noreferrer" |
| 180 | className="inline-flex items-center gap-1.5 rounded-md border border-fd-border bg-fd-background px-3 py-1.5 text-sm font-medium text-fd-foreground transition-colors hover:bg-fd-accent" |
| 181 | > |
| 182 | Playground |
| 183 | <ExternalLink className="h-3.5 w-3.5" /> |
| 184 | </a> |
| 185 | <a |
| 186 | href="https://request.composio.dev/boards/tool-requests" |
| 187 | target="_blank" |
| 188 | rel="noopener noreferrer" |
| 189 | className="inline-flex items-center gap-1.5 rounded-md border border-blue-500/30 bg-blue-500/10 px-3 py-1.5 text-sm font-medium text-blue-600 transition-colors hover:bg-blue-500/20 dark:text-blue-400" |
| 190 | > |
| 191 | <Grip className="h-3.5 w-3.5" /> |
| 192 | Request Tools |
| 193 | <ExternalLink className="h-3.5 w-3.5" /> |
| 194 | </a> |
| 195 | </div> |
| 196 | </div> |
| 197 | |
| 198 | {/* Cards */} |
| 199 | <Cards className="auto-rows-fr"> |
| 200 | <Card icon={<ShieldCheck />} title="Managed OAuth apps" href="/toolkits/managed-auth" description="Check which toolkits have managed OAuth" /> |
| 201 | <button |
| 202 | type="button" |
| 203 | aria-pressed={instantOnly} |
| 204 | onClick={() => setInstantOnly(value => !value)} |
| 205 | className={`not-prose rounded-xl border p-4 text-left transition-colors @max-lg:col-span-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 ${instantOnly ? 'border-blue-500 bg-blue-500/10' : 'border-fd-border bg-fd-card hover:bg-fd-accent'}`} |
| 206 | > |
| 207 | <InstantBolt filled={instantOnly} className={`mb-2 size-5 ${instantOnly ? 'text-blue-500' : 'text-fd-muted-foreground'}`} /> |
| 208 | <span className="block font-medium text-fd-card-foreground">Instant Tools</span> |
| 209 | <span className="mt-1 block text-sm text-fd-muted-foreground">Show toolkits with Instant tools</span> |
| 210 | </button> |
| 211 | <Card icon={<Wrench />} title="Meta Tools" href="/toolkits/meta-tools" description="The system tools every session gives your agent" /> |
| 212 | </Cards> |
| 213 | <Link href="/docs/instant-tools" className="inline-flex text-sm text-fd-primary hover:underline">Read the Instant Tools guide →</Link> |
| 214 | |
| 215 | {/* Search */} |
| 216 | <div className="relative"> |
| 217 | <Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-fd-muted-foreground" aria-hidden="true" /> |
| 218 | <input |
| 219 | type="text" |
| 220 | name="toolkit-search" |
| 221 | aria-label="Search toolkits" |
| 222 | placeholder="Search toolkits…" |
| 223 | autoComplete="off" |
| 224 | value={search} |
| 225 | onChange={(e) => setSearch(e.target.value)} |
| 226 | 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" |
| 227 | /> |
| 228 | </div> |
| 229 | |
| 230 | {/* Results count */} |
| 231 | {!instantUnavailable && <p className="text-sm text-fd-muted-foreground" role="status"> |
| 232 | {filteredToolkits.length} toolkit{filteredToolkits.length !== 1 ? 's' : ''} |
| 233 | {instantOnly && ' with Instant tools'} |
| 234 | {deferredSearch && ` matching "${deferredSearch}"`} |
| 235 | </p>} |
| 236 | {(instantOnly || search) && <button type="button" onClick={clearFilters} className="text-sm text-fd-primary hover:underline">Clear filters</button>} |
| 237 | {instantUnavailable && <div role="status" className="py-8 text-center text-sm text-fd-muted-foreground"> |
| 238 | {eligibilityFailed ? <><p>Instant toolkit availability could not be loaded.</p><button type="button" onClick={() => { setEligibilityFailed(false); setRetry(value => value + 1); }} className="mt-2 text-fd-primary hover:underline">Try again</button></> : 'Loading Instant toolkits…'} |
| 239 | </div>} |
| 240 | |
| 241 | {/* Popular Toolkits - only show when no search */} |
| 242 | {!instantOnly && !deferredSearch && popularToolkits.length > 0 && ( |
| 243 | <div> |
| 244 | <h2 className="mb-2 text-sm font-semibold text-fd-muted-foreground">Popular</h2> |
| 245 | <div className="divide-y divide-fd-border"> |
| 246 | {popularToolkits.map((toolkit) => ( |
| 247 | <ToolkitRow key={toolkit.slug} toolkit={toolkit} lazy={false} /> |
| 248 | ))} |
| 249 | </div> |
| 250 | </div> |
| 251 | )} |
| 252 | |
| 253 | {/* Alphabetically grouped list - table style */} |
| 254 | {!instantUnavailable && (groupedToolkits.length > 0 ? ( |
| 255 | <div className="space-y-6"> |
| 256 | {groupedToolkits.map(([letter, items]) => ( |
| 257 | <div key={letter}> |
| 258 | <h2 className="mb-2 text-sm font-semibold text-fd-muted-foreground">{letter}</h2> |
| 259 | <div className="divide-y divide-fd-border"> |
| 260 | {items.map((toolkit) => ( |
| 261 | <ToolkitRow key={toolkit.slug} toolkit={toolkit} /> |
| 262 | ))} |
| 263 | </div> |
| 264 | </div> |
| 265 | ))} |
| 266 | </div> |
| 267 | ) : ( |
| 268 | <div className="py-12 text-center"> |
| 269 | <p className="text-fd-muted-foreground">No toolkits found.</p> |
| 270 | <button |
| 271 | onClick={clearFilters} |
| 272 | className="mt-2 text-sm text-fd-primary hover:underline" |
| 273 | > |
| 274 | Clear filters |
| 275 | </button> |
| 276 | </div> |
| 277 | ))} |
| 278 | </div> |
| 279 | ); |
| 280 | } |