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 Link from 'next/link'; |
| 4 | import { useMemo, useState } from 'react'; |
| 5 | import { ArrowUpRight } from 'lucide-react'; |
| 6 | |
| 7 | /* ------------------------------------------------------------------ * |
| 8 | * Items come from each example's frontmatter (read in the route from the |
| 9 | * examples source). Title + description are the page's own; the `gallery` |
| 10 | * block in frontmatter supplies the category lane, toolkit logos, and |
| 11 | * featured flag. No per-example config lives in this component. |
| 12 | * ------------------------------------------------------------------ */ |
| 13 | |
| 14 | type Category = 'General agents' | 'Background agents' | 'Coding agents'; |
| 15 | |
| 16 | /** A resolved example, ready to render. Built in the route from frontmatter. */ |
| 17 | export interface GalleryItem { |
| 18 | title: string; |
| 19 | description: string; |
| 20 | href: string; |
| 21 | categories: Category[]; |
| 22 | logos: string[]; |
| 23 | featured?: boolean; |
| 24 | order?: number; |
| 25 | } |
| 26 | |
| 27 | /* ------------------------------------------------------------------ * |
| 28 | * Category styling — flat editorial tags in the brand accent palette. |
| 29 | * Full class strings are written out so Tailwind's JIT keeps them. |
| 30 | * ------------------------------------------------------------------ */ |
| 31 | |
| 32 | interface CatStyle { |
| 33 | tag: string; // mono pill on the card |
| 34 | dot: string; // filter-pill dot |
| 35 | bar: string; // top accent bar on hover |
| 36 | } |
| 37 | |
| 38 | const CATEGORY_STYLES: Record<Category, CatStyle> = { |
| 39 | 'General agents': { |
| 40 | tag: 'text-blue-500 border-blue-500/25 bg-blue-500/[0.06] dark:text-blue-400 dark:border-blue-400/25', |
| 41 | dot: 'bg-blue-500 dark:bg-blue-400', |
| 42 | bar: 'bg-blue-500 dark:bg-blue-400', |
| 43 | }, |
| 44 | 'Background agents': { |
| 45 | tag: 'text-violet-500 border-violet-500/25 bg-violet-500/[0.06] dark:text-violet-400 dark:border-violet-400/25', |
| 46 | dot: 'bg-violet-500 dark:bg-violet-400', |
| 47 | bar: 'bg-violet-500 dark:bg-violet-400', |
| 48 | }, |
| 49 | 'Coding agents': { |
| 50 | tag: 'text-emerald-600 border-emerald-500/25 bg-emerald-500/[0.06] dark:text-emerald-400 dark:border-emerald-400/25', |
| 51 | dot: 'bg-emerald-600 dark:bg-emerald-400', |
| 52 | bar: 'bg-emerald-600 dark:bg-emerald-400', |
| 53 | }, |
| 54 | }; |
| 55 | |
| 56 | const CATEGORIES: ('Featured' | Category)[] = [ |
| 57 | 'Featured', |
| 58 | 'General agents', |
| 59 | 'Background agents', |
| 60 | 'Coding agents', |
| 61 | ]; |
| 62 | |
| 63 | function logoUrl(name: string) { |
| 64 | return `https://logos.composio.dev/api/${name}`; |
| 65 | } |
| 66 | |
| 67 | /* ------------------------------------------------------------------ * |
| 68 | * Card |
| 69 | * ------------------------------------------------------------------ */ |
| 70 | |
| 71 | function ExampleCard({ ex, index }: { ex: GalleryItem; index: number }) { |
| 72 | // The first category drives the hover accent bar. |
| 73 | const primary = CATEGORY_STYLES[ex.categories[0] ?? 'General agents']; |
| 74 | return ( |
| 75 | <Link |
| 76 | href={ex.href} |
| 77 | style={{ animationDelay: `${Math.min(index, 8) * 55}ms` }} |
| 78 | className="exg-card group relative flex flex-col border border-fd-border bg-fd-card [text-decoration:none] transition-[transform,box-shadow,background-color] duration-200 ease-out hover:-translate-x-[3px] hover:-translate-y-[3px] hover:bg-fd-card hover:shadow-[6px_6px_0_0_color-mix(in_srgb,var(--composio-brand)_24%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--composio-brand)] focus-visible:ring-offset-2 focus-visible:ring-offset-fd-background" |
| 79 | > |
| 80 | {/* top accent bar — grows in on hover */} |
| 81 | <span |
| 82 | className={`absolute left-0 top-0 h-[2px] w-0 transition-[width] duration-300 ease-out group-hover:w-full ${primary.bar}`} |
| 83 | /> |
| 84 | |
| 85 | <div className="flex items-start justify-between gap-4 p-5 pb-0"> |
| 86 | <div className="flex flex-wrap items-center gap-1.5"> |
| 87 | {ex.categories.map((cat) => ( |
| 88 | <span |
| 89 | key={cat} |
| 90 | className={`inline-flex items-center border px-2 py-1 font-mono text-[10px] font-medium uppercase tracking-wide ${CATEGORY_STYLES[cat].tag}`} |
| 91 | > |
| 92 | {cat} |
| 93 | </span> |
| 94 | ))} |
| 95 | </div> |
| 96 | {ex.logos.length > 0 && ( |
| 97 | <div className="flex shrink-0 items-center -space-x-1.5"> |
| 98 | {ex.logos.map((logo) => ( |
| 99 | // eslint-disable-next-line nextjs/no-img-element |
| 100 | <img |
| 101 | key={logo} |
| 102 | alt={logo} |
| 103 | src={logoUrl(logo)} |
| 104 | // White tile in both themes (matches the brand's logo chips) so |
| 105 | // monochrome marks like GitHub stay visible on dark cards. |
| 106 | className="h-7 w-7 rounded-[5px] border border-black/10 bg-white object-contain p-1 ring-2 ring-fd-card" |
| 107 | loading="lazy" |
| 108 | /> |
| 109 | ))} |
| 110 | </div> |
| 111 | )} |
| 112 | </div> |
| 113 | |
| 114 | <div className="flex flex-1 flex-col gap-2 p-5 pt-4"> |
| 115 | <h3 className="font-sans text-lg font-medium leading-snug text-fd-foreground [text-wrap:balance]"> |
| 116 | {ex.title} |
| 117 | </h3> |
| 118 | <p className="line-clamp-3 text-sm leading-relaxed text-fd-muted-foreground"> |
| 119 | {ex.description} |
| 120 | </p> |
| 121 | </div> |
| 122 | |
| 123 | <div className="mt-auto flex items-center gap-1.5 border-t border-fd-border px-5 py-3 font-mono text-[11px] uppercase tracking-wide text-fd-muted-foreground transition-colors group-hover:text-[var(--composio-brand)]"> |
| 124 | Read guide |
| 125 | <ArrowUpRight className="h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5" /> |
| 126 | </div> |
| 127 | </Link> |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | /* ------------------------------------------------------------------ * |
| 132 | * Gallery |
| 133 | * ------------------------------------------------------------------ */ |
| 134 | |
| 135 | export function ExamplesGallery({ items }: { items: GalleryItem[] }) { |
| 136 | const [active, setActive] = useState<'Featured' | Category>('Featured'); |
| 137 | |
| 138 | const resolved = useMemo<GalleryItem[]>( |
| 139 | () => [...items].sort((a, b) => (a.order ?? 99) - (b.order ?? 99)), |
| 140 | [items], |
| 141 | ); |
| 142 | |
| 143 | const visible = useMemo(() => { |
| 144 | if (active === 'Featured') return resolved.filter((e) => e.featured); |
| 145 | return resolved.filter((e) => e.categories.includes(active)); |
| 146 | }, [active, resolved]); |
| 147 | |
| 148 | const countFor = (label: 'Featured' | Category) => |
| 149 | label === 'Featured' |
| 150 | ? resolved.filter((e) => e.featured).length |
| 151 | : resolved.filter((e) => e.categories.includes(label)).length; |
| 152 | |
| 153 | return ( |
| 154 | <div className="exg w-full px-5 py-12 [grid-area:main] sm:px-8 lg:px-12 lg:py-16"> |
| 155 | {/* Hero */} |
| 156 | <header className="mb-10 max-w-3xl"> |
| 157 | <p className="mb-4 font-mono text-[11px] font-medium uppercase tracking-[0.22em] text-fd-muted-foreground"> |
| 158 | Examples |
| 159 | </p> |
| 160 | <h1 className="font-sans text-4xl font-normal leading-[1.05] tracking-tight text-fd-foreground sm:text-5xl lg:text-6xl"> |
| 161 | Featured examples |
| 162 | </h1> |
| 163 | <p className="mt-5 max-w-2xl text-base leading-relaxed text-fd-muted-foreground sm:text-lg"> |
| 164 | End-to-end builds that wire Composio into working agents. Each one is a |
| 165 | complete project you can read top to bottom and run. |
| 166 | </p> |
| 167 | <Link |
| 168 | href="/examples/sdk-examples" |
| 169 | className="mt-4 inline-flex items-center gap-1.5 text-sm font-medium text-fd-primary underline underline-offset-4" |
| 170 | > |
| 171 | Browse TypeScript and Python SDK examples |
| 172 | <ArrowUpRight className="h-4 w-4" aria-hidden="true" /> |
| 173 | </Link> |
| 174 | </header> |
| 175 | |
| 176 | {/* Filter pills */} |
| 177 | <div className="mb-9 flex flex-wrap gap-2 border-b border-fd-border pb-6"> |
| 178 | {CATEGORIES.map((label) => { |
| 179 | const isActive = active === label; |
| 180 | const count = countFor(label); |
| 181 | const dot = label === 'Featured' ? undefined : CATEGORY_STYLES[label].dot; |
| 182 | return ( |
| 183 | <button |
| 184 | key={label} |
| 185 | type="button" |
| 186 | onClick={() => setActive(label)} |
| 187 | aria-pressed={isActive} |
| 188 | className={`inline-flex items-center gap-2 border px-3.5 py-1.5 font-mono text-xs font-medium uppercase tracking-wide transition-colors duration-150 ${ |
| 189 | isActive |
| 190 | ? 'border-fd-foreground bg-fd-foreground text-fd-background' |
| 191 | : 'border-fd-border bg-fd-card text-fd-muted-foreground hover:border-fd-foreground/30 hover:text-fd-foreground' |
| 192 | }`} |
| 193 | > |
| 194 | {label === 'Featured' ? ( |
| 195 | <span |
| 196 | className={`h-2 w-2 ${isActive ? 'bg-fd-background' : 'bg-[var(--composio-brand)]'}`} |
| 197 | /> |
| 198 | ) : ( |
| 199 | <span className={`h-2 w-2 rounded-full ${dot}`} /> |
| 200 | )} |
| 201 | {label} |
| 202 | <span |
| 203 | className={`tabular-nums ${isActive ? 'text-fd-background/55' : 'text-fd-muted-foreground/50'}`} |
| 204 | > |
| 205 | {count} |
| 206 | </span> |
| 207 | </button> |
| 208 | ); |
| 209 | })} |
| 210 | </div> |
| 211 | |
| 212 | {/* Grid */} |
| 213 | {visible.length > 0 ? ( |
| 214 | <div className="grid grid-cols-1 gap-5 sm:grid-cols-2 xl:grid-cols-3"> |
| 215 | {visible.map((ex, i) => ( |
| 216 | <ExampleCard key={ex.href} ex={ex} index={i} /> |
| 217 | ))} |
| 218 | </div> |
| 219 | ) : ( |
| 220 | <div className="border border-dashed border-fd-border px-6 py-16 text-center font-mono text-sm text-fd-muted-foreground"> |
| 221 | More examples in this category are on the way. |
| 222 | </div> |
| 223 | )} |
| 224 | |
| 225 | <style>{` |
| 226 | .exg-card { |
| 227 | opacity: 0; |
| 228 | animation: exg-rise 0.45s cubic-bezier(0.22, 1, 0.36, 1) forwards; |
| 229 | } |
| 230 | @keyframes exg-rise { |
| 231 | from { opacity: 0; transform: translateY(12px); } |
| 232 | to { opacity: 1; transform: translateY(0); } |
| 233 | } |
| 234 | @media (prefers-reduced-motion: reduce) { |
| 235 | .exg-card { animation: none; opacity: 1; } |
| 236 | .exg-card * { transition: none !important; } |
| 237 | } |
| 238 | `}</style> |
| 239 | </div> |
| 240 | ); |
| 241 | } |