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 { useDeferredValue, useMemo, useState } from 'react'; |
| 4 | import Link from 'next/link'; |
| 5 | import { Search, Wrench } from 'lucide-react'; |
| 6 | import type { ToolkitKnowledgeSummary } from '@/lib/knowledge/catalog'; |
| 7 | import { getToolkitKnowledgeHref } from '@/lib/knowledge/toolkit-routing'; |
| 8 | |
| 9 | const TOOLKIT_PAGE_SIZE = 60; |
| 10 | |
| 11 | export function ToolkitGrid({ toolkits }: { toolkits: ToolkitKnowledgeSummary[] }) { |
| 12 | const [query, setQuery] = useState(''); |
| 13 | const [visibleCount, setVisibleCount] = useState(TOOLKIT_PAGE_SIZE); |
| 14 | const deferredQuery = useDeferredValue(query.trim().toLowerCase()); |
| 15 | const filtered = useMemo(() => { |
| 16 | if (!deferredQuery) return toolkits; |
| 17 | return toolkits.filter((toolkit) => |
| 18 | toolkit.name.toLowerCase().includes(deferredQuery) || |
| 19 | toolkit.slug.toLowerCase().includes(deferredQuery) || |
| 20 | toolkit.category?.toLowerCase().includes(deferredQuery), |
| 21 | ); |
| 22 | }, [deferredQuery, toolkits]); |
| 23 | const visible = deferredQuery ? filtered : filtered.slice(0, visibleCount); |
| 24 | const remaining = filtered.length - visible.length; |
| 25 | |
| 26 | return ( |
| 27 | <div> |
| 28 | <label htmlFor="toolkit-search" className="mb-2 block text-sm font-medium">Search toolkits</label> |
| 29 | <div className="relative max-w-xl"> |
| 30 | <Search className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fd-muted-foreground" aria-hidden="true" /> |
| 31 | <input |
| 32 | id="toolkit-search" |
| 33 | name="toolkit-search" |
| 34 | type="search" |
| 35 | value={query} |
| 36 | onChange={(event) => setQuery(event.target.value)} |
| 37 | placeholder="Search by toolkit name or slug" |
| 38 | autoComplete="off" |
| 39 | className="h-11 w-full border border-fd-border bg-fd-background pl-10 pr-4 text-sm outline-none placeholder:text-fd-muted-foreground focus-visible:border-fd-primary focus-visible:ring-2 focus-visible:ring-fd-primary/20" |
| 40 | /> |
| 41 | </div> |
| 42 | <p className="mt-3 text-sm text-fd-muted-foreground" aria-live="polite"> |
| 43 | {filtered.length} toolkit{filtered.length === 1 ? '' : 's'} |
| 44 | {deferredQuery ? ` matching “${query.trim()}”` : ' with public knowledge'} |
| 45 | </p> |
| 46 | |
| 47 | {filtered.length > 0 ? ( |
| 48 | <> |
| 49 | <div className="mt-7 grid border-l border-t border-fd-border sm:grid-cols-2 lg:grid-cols-3"> |
| 50 | {visible.map((toolkit) => ( |
| 51 | <Link |
| 52 | key={toolkit.slug} |
| 53 | href={getToolkitKnowledgeHref(toolkit)} |
| 54 | className="group flex items-center gap-4 border-b border-r border-fd-border bg-fd-background p-4 transition-colors hover:bg-fd-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-fd-ring" |
| 55 | > |
| 56 | <span className="flex size-10 shrink-0 items-center justify-center border border-fd-border bg-fd-background"> |
| 57 | {toolkit.logo |
| 58 | ? <img src={toolkit.logo} alt="" width={28} height={28} className="size-7 object-contain" loading="lazy" /> |
| 59 | : <Wrench className="size-5 text-fd-muted-foreground" aria-hidden="true" />} |
| 60 | </span> |
| 61 | <span className="min-w-0"> |
| 62 | <span className="block truncate font-medium group-hover:text-fd-primary">{toolkit.name}</span> |
| 63 | <span className="mt-0.5 block text-xs text-fd-muted-foreground"> |
| 64 | {toolkit.knowledgeCount} resource{toolkit.knowledgeCount === 1 ? '' : 's'} |
| 65 | </span> |
| 66 | </span> |
| 67 | </Link> |
| 68 | ))} |
| 69 | </div> |
| 70 | {remaining > 0 && ( |
| 71 | <button |
| 72 | type="button" |
| 73 | onClick={() => setVisibleCount((current) => current + TOOLKIT_PAGE_SIZE)} |
| 74 | className="mt-5 border border-fd-border px-4 py-2 text-sm font-medium transition-colors hover:bg-fd-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring" |
| 75 | > |
| 76 | Show {Math.min(remaining, TOOLKIT_PAGE_SIZE)} more |
| 77 | </button> |
| 78 | )} |
| 79 | </> |
| 80 | ) : ( |
| 81 | <div className="mt-7 border border-fd-border p-8 text-center text-sm text-fd-muted-foreground"> |
| 82 | No toolkits match “{query.trim()}”. |
| 83 | </div> |
| 84 | )} |
| 85 | </div> |
| 86 | ); |
| 87 | } |