Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
tsx 283 lines 10.7 KB
Raw
1 'use client';
2
3 import { Check, RefreshCw } from 'lucide-react';
4 import { motion, useReducedMotion } from 'motion/react';
5 import { useCallback, useEffect, useRef, useState } from 'react';
6
7 const LOGO_CDN = 'https://logos.composio.dev/api';
8
9 /** Landing /dev accent (`--brand-foryou`). */
10 const BRAND = '#51a2ff';
11 /** Landing floating-card shadow. */
12 const CARD_SHADOW = '0 24px 70px -10px rgba(0,0,0,0.7)';
13
14 const CONNECTIONS: { slug: string; name: string; account: string }[] = [
15 { slug: 'gmail', name: 'Gmail', account: 'work@acme.com' },
16 { slug: 'notion', name: 'Notion', account: 'acme-workspace' },
17 { slug: 'github', name: 'GitHub', account: 'acme-bot' },
18 ];
19
20 /** Rotating access-token suffixes, so each refresh visibly mints a fresh token. */
21 const TOKENS = ['9f3a', '2c7d', 'b18e', '6a04', 'd52f'];
22
23 /** ms between simulated 30-minute refresh ticks. */
24 const CYCLE_MS = 4200;
25
26 /**
27 * Orthogonal elbow connector (the /dev page shape): leave `from`'s right edge
28 * horizontally, step vertically at the midpoint, then run horizontally into
29 * `to`'s left edge, with rounded corners. Measured relative to the container.
30 */
31 function elbowPath(c: DOMRect, from: DOMRect, to: DOMRect, r = 10): string {
32 const sx = from.right - c.left;
33 const sy = from.top + from.height / 2 - c.top;
34 const ex = to.left - c.left;
35 const ey = to.top + to.height / 2 - c.top;
36 const midX = sx + (ex - sx) * 0.5;
37 const dy = Math.sign(ey - sy) || 1;
38 const rr = Math.min(r, Math.abs(ex - sx) / 2, Math.abs(ey - sy) / 2);
39 if (rr < 1) return `M ${sx} ${sy} L ${ex} ${ey}`;
40 return (
41 `M ${sx} ${sy} L ${midX - rr} ${sy} ` +
42 `Q ${midX} ${sy} ${midX} ${sy + dy * rr} ` +
43 `L ${midX} ${ey - dy * rr} ` +
44 `Q ${midX} ${ey} ${midX + rr} ${ey} ` +
45 `L ${ex} ${ey}`
46 );
47 }
48
49 /**
50 * ConnectionRefreshVisual — Composio's automatic OAuth token refresh, drawn in
51 * the landing /dev visual language: bare dark floating cards (#0a0a0a, hairline
52 * white borders, JetBrains Mono) wired together with measured SVG elbow
53 * connectors in the for-you brand blue. A central refresh node fans out to the
54 * user's live connections (Gmail, Notion, GitHub). On every tick (one simulated
55 * 30-minute interval) a pulse travels each wire, the access token rotates, and
56 * the connection flashes `refreshed` while staying `ACTIVE`. Paths are computed
57 * from live geometry so the fanout stays aligned across breakpoints.
58 */
59 export function ConnectionRefreshVisual() {
60 const rootRef = useRef<HTMLDivElement>(null);
61 const hubRef = useRef<HTMLDivElement>(null);
62 const cardRefs = useRef<(HTMLDivElement | null)[]>([]);
63 const [paths, setPaths] = useState<string[]>([]);
64 const [tick, setTick] = useState(0);
65 const [active, setActive] = useState(false);
66 const reduce = useReducedMotion();
67
68 const calc = useCallback(() => {
69 const root = rootRef.current;
70 const hub = hubRef.current;
71 if (!root || !hub) return;
72 const cr = root.getBoundingClientRect();
73 const from = hub.getBoundingClientRect();
74 const next: string[] = [];
75 for (const ref of cardRefs.current) {
76 if (!ref) continue;
77 next.push(elbowPath(cr, from, ref.getBoundingClientRect()));
78 }
79 setPaths(next);
80 }, []);
81
82 useEffect(() => {
83 calc();
84 const t = setTimeout(calc, 120);
85 window.addEventListener('resize', calc);
86 const root = rootRef.current;
87 const ro = root ? new ResizeObserver(() => calc()) : null;
88 if (root && ro) ro.observe(root);
89 return () => {
90 clearTimeout(t);
91 window.removeEventListener('resize', calc);
92 ro?.disconnect();
93 };
94 }, [calc]);
95
96 // Only run the refresh loop while on screen.
97 useEffect(() => {
98 const el = rootRef.current;
99 if (!el) return;
100 const io = new IntersectionObserver(
101 ([e]) => setActive(!!e?.isIntersecting),
102 { threshold: 0.4 }
103 );
104 io.observe(el);
105 return () => io.disconnect();
106 }, []);
107
108 useEffect(() => {
109 if (!active || reduce) return;
110 const id = setInterval(() => setTick((t) => t + 1), CYCLE_MS);
111 return () => clearInterval(id);
112 }, [active, reduce]);
113
114 return (
115 <div className="not-prose my-8 font-mono">
116 <div
117 ref={rootRef}
118 className="relative flex flex-col gap-4 md:block md:h-[320px]"
119 >
120 {/* ── connector overlay (md and up) ── */}
121 <svg
122 aria-hidden="true"
123 className="pointer-events-none absolute inset-0 z-0 hidden size-full overflow-visible md:block"
124 fill="none"
125 style={{ color: BRAND }}
126 >
127 {paths.map((d, i) => (
128 <path
129 key={CONNECTIONS[i]?.slug ?? i}
130 d={d}
131 opacity={0.18}
132 stroke="currentColor"
133 strokeWidth={1}
134 />
135 ))}
136 </svg>
137
138 {/* ── traveling refresh pulses, re-fired each tick ── */}
139 {!reduce &&
140 paths.map((d, i) => (
141 <motion.span
142 key={`${CONNECTIONS[i]?.slug ?? i}-${tick}`}
143 aria-hidden="true"
144 className="absolute left-0 top-0 z-[1] hidden size-[7px] rounded-full md:block"
145 style={{
146 offsetPath: `path('${d}')`,
147 offsetDistance: '0%',
148 offsetRotate: '0deg',
149 background: BRAND,
150 boxShadow: `0 0 10px 2px ${BRAND}`,
151 }}
152 initial={{ offsetDistance: '0%', opacity: 0 }}
153 animate={{
154 offsetDistance: '100%',
155 opacity: [0, 1, 1, 0],
156 }}
157 transition={{ duration: 0.85, delay: i * 0.12, ease: 'easeInOut' }}
158 />
159 ))}
160
161 {/* ── hub: bare Composio logo ── */}
162 <div className="relative z-10 flex justify-center md:absolute md:top-1/2 md:left-0 md:block md:w-[180px] md:-translate-y-1/2">
163 <span ref={hubRef} className="inline-flex">
164 <img
165 alt="Composio"
166 className="h-6 w-auto object-contain dark:hidden"
167 draggable={false}
168 src="/Composio Logo.svg"
169 />
170 <img
171 alt="Composio"
172 className="hidden h-6 w-auto object-contain dark:block"
173 draggable={false}
174 src="/Composio Logo Dark.svg"
175 />
176 </span>
177 </div>
178
179 {/* ── "every 30 min" badge, centered over the wiring ── */}
180 <div className="relative z-20 flex justify-center md:absolute md:top-1/2 md:left-1/2 md:-translate-x-1/2 md:-translate-y-1/2">
181 <div
182 className="inline-flex items-center gap-1.5 rounded-full border bg-fd-background px-3 py-1.5 text-[11px] font-medium shadow-sm"
183 style={{
184 borderColor: 'color-mix(in srgb, ' + BRAND + ' 35%, transparent)',
185 color: BRAND,
186 }}
187 >
188 <motion.span
189 className="inline-flex"
190 animate={reduce ? undefined : { rotate: tick * 360 }}
191 transition={{ duration: 0.85, ease: 'easeInOut' }}
192 >
193 <RefreshCw aria-hidden="true" className="size-3.5" />
194 </motion.span>
195 every 30 min
196 </div>
197 </div>
198
199 {/* ── connection cards ── */}
200 <div className="relative z-10 flex flex-col gap-3 md:absolute md:inset-y-0 md:right-0 md:w-[320px] md:justify-center md:gap-4">
201 {CONNECTIONS.map((conn, i) => {
202 const suffix = TOKENS[(tick + i) % TOKENS.length];
203 return (
204 <div
205 key={conn.slug}
206 ref={(el) => {
207 cardRefs.current[i] = el;
208 }}
209 className="overflow-hidden border border-white/10 bg-[#0a0a0a]"
210 style={{ boxShadow: CARD_SHADOW }}
211 >
212 <div className="flex items-center gap-2 border-b border-white/[0.06] bg-white/[0.02] px-2.5 py-2">
213 <span className="flex size-6 items-center justify-center rounded-md bg-white ring-1 ring-white/10">
214 <img
215 alt=""
216 aria-hidden="true"
217 className="size-[15px] object-contain"
218 draggable={false}
219 src={`${LOGO_CDN}/${conn.slug}`}
220 />
221 </span>
222 <span className="text-[12px] text-white/80">{conn.name}</span>
223 <code className="ml-auto text-[10px] text-white/35">
224 {conn.account}
225 </code>
226 </div>
227 <div className="flex items-center gap-2.5 px-2.5 py-2">
228 <span className="inline-flex items-center gap-1.5 text-[10px] text-green-400">
229 <span className="size-1.5 rounded-full bg-green-400" />
230 ACTIVE
231 </span>
232 {/* token rotates on each refresh */}
233 <code className="text-[11px] text-white/45">
234 oauth&nbsp;&middot;&nbsp;&bull;&bull;&bull;&bull;
235 <motion.span
236 key={suffix}
237 className="text-white/70"
238 initial={reduce ? false : { color: BRAND, opacity: 0.4 }}
239 animate={{ color: 'rgba(255,255,255,0.7)', opacity: 1 }}
240 transition={{ duration: 0.6 }}
241 >
242 {suffix}
243 </motion.span>
244 </code>
245 {/* refreshed flash, keyed to the tick */}
246 <motion.span
247 key={`flash-${conn.slug}-${tick}`}
248 aria-hidden="true"
249 className="ml-auto inline-flex items-center gap-1 text-[10px] text-green-400"
250 initial={reduce ? false : { opacity: 0, y: -2 }}
251 animate={
252 reduce
253 ? { opacity: 1 }
254 : { opacity: [0, 1, 1, 0], y: 0 }
255 }
256 transition={{
257 duration: 1.6,
258 delay: 0.7 + i * 0.12,
259 times: [0, 0.15, 0.7, 1],
260 }}
261 >
262 <Check className="size-3" />
263 refreshed
264 </motion.span>
265 </div>
266 </div>
267 );
268 })}
269 </div>
270 </div>
271
272 {/* plain caption — page text, no box */}
273 <p className="mt-6 text-center text-[10px] text-fd-foreground/45">
274 Composio rotates every connection&rsquo;s token on a schedule{' '}
275 <span aria-hidden="true" style={{ color: BRAND }}>
276 →
277 </span>{' '}
278 connections stay <span className="text-green-400">ACTIVE</span> with no
279 work from you
280 </p>
281 </div>
282 );
283 }