Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | 'use client'; |
| 2 | |
| 3 | import { useEffect, useRef, useState } from 'react'; |
| 4 | import { AnimatePresence, motion } from 'motion/react'; |
| 5 | |
| 6 | const LOGO_CDN = 'https://logos.composio.dev/api'; |
| 7 | |
| 8 | interface ChatSkin { |
| 9 | name: string; |
| 10 | subtitle?: string; |
| 11 | logo?: string; |
| 12 | invertLogo?: boolean; |
| 13 | bg: string; |
| 14 | userBubbleBg: string; |
| 15 | inputBg: string; |
| 16 | textColor: string; |
| 17 | textMuted: string; |
| 18 | borderColor: string; |
| 19 | accent: string; |
| 20 | modelLabel: string; |
| 21 | radius: string; |
| 22 | } |
| 23 | |
| 24 | type ChatItem = |
| 25 | | { type: 'user'; content: string } |
| 26 | | { type: 'tool'; name: string } |
| 27 | | { type: 'assistant'; content: string }; |
| 28 | |
| 29 | type ActiveTool = |
| 30 | | { |
| 31 | kind: 'search'; |
| 32 | query: string; |
| 33 | tools: { slug: string; name: string; description: string }[]; |
| 34 | } |
| 35 | | { |
| 36 | kind: 'execute'; |
| 37 | sessionId: string; |
| 38 | tool: string; |
| 39 | toolkitSlug: string; |
| 40 | params: { key: string; value: string }[]; |
| 41 | status: string; |
| 42 | } |
| 43 | | { |
| 44 | kind: 'workbench'; |
| 45 | task: string; |
| 46 | code: string; |
| 47 | result: string; |
| 48 | }; |
| 49 | |
| 50 | interface Frame { |
| 51 | /** Indices into `chatItems` to render. */ |
| 52 | items: number[]; |
| 53 | /** Index into `tools`; null hides the floating overlay. */ |
| 54 | toolIdx: number | null; |
| 55 | /** Whether the thinking-dots indicator is showing. */ |
| 56 | thinking: boolean; |
| 57 | /** ms before advancing to the next frame. */ |
| 58 | delay: number; |
| 59 | } |
| 60 | |
| 61 | interface Example { |
| 62 | skin: ChatSkin; |
| 63 | chatItems: ChatItem[]; |
| 64 | tools: ActiveTool[]; |
| 65 | timeline: Frame[]; |
| 66 | } |
| 67 | |
| 68 | function findLastToolIdx(timeline: Frame[], currentIdx: number): number | null { |
| 69 | for (let i = Math.min(currentIdx, timeline.length - 1); i >= 0; i--) { |
| 70 | const t = timeline[i]?.toolIdx; |
| 71 | if (t !== null && t !== undefined) return t; |
| 72 | } |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | const ACTIVE_TOOL_LABELS: Record<ActiveTool['kind'], string> = { |
| 77 | search: 'COMPOSIO_SEARCH_TOOLS', |
| 78 | execute: 'COMPOSIO_EXECUTE_TOOL', |
| 79 | workbench: 'COMPOSIO_WORKBENCH', |
| 80 | }; |
| 81 | |
| 82 | const EXAMPLES: Example[] = [ |
| 83 | { |
| 84 | skin: { |
| 85 | name: 'Claude', |
| 86 | subtitle: 'Cowork', |
| 87 | logo: '/images/clients/claude.svg', |
| 88 | bg: 'var(--hero-surface)', |
| 89 | userBubbleBg: 'var(--hero-bubble)', |
| 90 | inputBg: 'var(--hero-surface-2)', |
| 91 | textColor: 'var(--hero-text)', |
| 92 | textMuted: 'var(--hero-text-muted)', |
| 93 | borderColor: 'var(--hero-border)', |
| 94 | accent: '#c4956a', |
| 95 | modelLabel: 'Sonnet 4.6', |
| 96 | radius: '20px', |
| 97 | }, |
| 98 | chatItems: [ |
| 99 | { |
| 100 | type: 'user', |
| 101 | content: |
| 102 | 'Summarize my Slack from the last 48 hours and send a digest to #daily-digest.', |
| 103 | }, |
| 104 | { type: 'tool', name: 'COMPOSIO SEARCH TOOLS' }, |
| 105 | { type: 'tool', name: 'COMPOSIO WORKBENCH' }, |
| 106 | { type: 'tool', name: 'COMPOSIO EXECUTE TOOL' }, |
| 107 | { |
| 108 | type: 'assistant', |
| 109 | content: |
| 110 | "Here's your 48-hour Slack digest. 3 critical items need your attention today.", |
| 111 | }, |
| 112 | ], |
| 113 | tools: [ |
| 114 | { |
| 115 | kind: 'search', |
| 116 | query: 'fetch slack messages and summarize', |
| 117 | tools: [ |
| 118 | { |
| 119 | slug: 'slack', |
| 120 | name: 'SLACK_FETCH_MESSAGES', |
| 121 | description: 'Fetch messages from a channel', |
| 122 | }, |
| 123 | { |
| 124 | slug: 'slack', |
| 125 | name: 'SLACK_LIST_CHANNELS', |
| 126 | description: 'List channels in a workspace', |
| 127 | }, |
| 128 | { |
| 129 | slug: 'slack', |
| 130 | name: 'SLACK_SEND_MESSAGE', |
| 131 | description: 'Post a message to a channel', |
| 132 | }, |
| 133 | ], |
| 134 | }, |
| 135 | { |
| 136 | kind: 'workbench', |
| 137 | task: 'Classify & summarize', |
| 138 | code: `files = glob('/tmp/*.json') |
| 139 | all_msgs = [] |
| 140 | for f in files: |
| 141 | all_msgs += json.load(open(f)) |
| 142 | |
| 143 | ranked = invoke_llm( |
| 144 | f'Classify {len(all_msgs)} messages' |
| 145 | ' by urgency: P0, P1, P2' |
| 146 | )`, |
| 147 | result: '3 critical, 12 important', |
| 148 | }, |
| 149 | { |
| 150 | kind: 'execute', |
| 151 | sessionId: 'sx-7k2m', |
| 152 | tool: 'SLACK_SEND_MESSAGE', |
| 153 | toolkitSlug: 'slack', |
| 154 | params: [ |
| 155 | { key: 'channel', value: '#daily-digest' }, |
| 156 | { key: 'text', value: 'summary (1,240 chars)' }, |
| 157 | ], |
| 158 | status: '200 OK · message sent', |
| 159 | }, |
| 160 | ], |
| 161 | timeline: [ |
| 162 | { items: [0], toolIdx: null, thinking: false, delay: 900 }, |
| 163 | { items: [0], toolIdx: null, thinking: true, delay: 600 }, |
| 164 | { items: [0, 1], toolIdx: 0, thinking: false, delay: 2400 }, |
| 165 | { items: [0, 1, 2], toolIdx: 1, thinking: false, delay: 2800 }, |
| 166 | { items: [0, 1, 2, 3], toolIdx: 2, thinking: false, delay: 2200 }, |
| 167 | { items: [0, 1, 2, 3, 4], toolIdx: null, thinking: false, delay: 2400 }, |
| 168 | ], |
| 169 | }, |
| 170 | { |
| 171 | skin: { |
| 172 | name: 'ChatGPT', |
| 173 | subtitle: 'Codex', |
| 174 | logo: '/images/clients/chatgpt.png', |
| 175 | bg: 'var(--hero-surface)', |
| 176 | userBubbleBg: 'var(--hero-bubble)', |
| 177 | inputBg: 'var(--hero-surface-2)', |
| 178 | textColor: 'var(--hero-text)', |
| 179 | textMuted: 'var(--hero-text-muted)', |
| 180 | borderColor: 'var(--hero-border)', |
| 181 | accent: '#10a37f', |
| 182 | modelLabel: 'GPT-4.1', |
| 183 | radius: '14px', |
| 184 | }, |
| 185 | chatItems: [ |
| 186 | { |
| 187 | type: 'user', |
| 188 | content: |
| 189 | 'Download all 250 SVGs from our Figma file and upload them to Google Drive.', |
| 190 | }, |
| 191 | { type: 'tool', name: 'COMPOSIO SEARCH TOOLS' }, |
| 192 | { type: 'tool', name: 'COMPOSIO WORKBENCH' }, |
| 193 | { |
| 194 | type: 'assistant', |
| 195 | content: |
| 196 | 'Exported 250 SVGs from Figma and uploaded all files to Drive/assets/icons.', |
| 197 | }, |
| 198 | ], |
| 199 | tools: [ |
| 200 | { |
| 201 | kind: 'search', |
| 202 | query: 'export figma assets and upload to drive', |
| 203 | tools: [ |
| 204 | { |
| 205 | slug: 'figma', |
| 206 | name: 'FIGMA_GET_FILE_NODES', |
| 207 | description: 'Get nodes from a Figma file', |
| 208 | }, |
| 209 | { |
| 210 | slug: 'figma', |
| 211 | name: 'FIGMA_EXPORT_ASSETS', |
| 212 | description: 'Export assets as SVG/PNG', |
| 213 | }, |
| 214 | { |
| 215 | slug: 'googledrive', |
| 216 | name: 'GOOGLEDRIVE_UPLOAD_FILE', |
| 217 | description: 'Upload a file to Drive', |
| 218 | }, |
| 219 | ], |
| 220 | }, |
| 221 | { |
| 222 | kind: 'workbench', |
| 223 | task: 'Export Figma assets', |
| 224 | code: `nodes = run_composio_tool( |
| 225 | 'FIGMA_GET_FILE_NODES', |
| 226 | file_key=file_key, |
| 227 | ) |
| 228 | svgs = [] |
| 229 | for batch in chunks(nodes, 50): |
| 230 | result = run_composio_tool( |
| 231 | 'FIGMA_EXPORT_ASSETS', |
| 232 | ids=[n['id'] for n in batch], |
| 233 | )`, |
| 234 | result: '250 SVGs exported', |
| 235 | }, |
| 236 | ], |
| 237 | timeline: [ |
| 238 | { items: [0], toolIdx: null, thinking: false, delay: 900 }, |
| 239 | { items: [0], toolIdx: null, thinking: true, delay: 600 }, |
| 240 | { items: [0, 1], toolIdx: 0, thinking: false, delay: 2400 }, |
| 241 | { items: [0, 1, 2], toolIdx: 1, thinking: false, delay: 3000 }, |
| 242 | { items: [0, 1, 2, 3], toolIdx: null, thinking: false, delay: 2400 }, |
| 243 | ], |
| 244 | }, |
| 245 | { |
| 246 | skin: { |
| 247 | name: 'Your AI Agent', |
| 248 | bg: 'var(--hero-surface)', |
| 249 | userBubbleBg: 'var(--hero-bubble)', |
| 250 | inputBg: 'var(--hero-surface-2)', |
| 251 | textColor: 'var(--hero-text)', |
| 252 | textMuted: 'var(--hero-text-muted)', |
| 253 | borderColor: 'rgba(0,7,205,0.22)', |
| 254 | accent: '#0007cd', |
| 255 | modelLabel: 'llama-3.3-70b', |
| 256 | radius: '20px', |
| 257 | }, |
| 258 | chatItems: [ |
| 259 | { |
| 260 | type: 'user', |
| 261 | content: |
| 262 | 'Triage all open Sentry errors and create Linear issues for P0s.', |
| 263 | }, |
| 264 | { type: 'tool', name: 'COMPOSIO SEARCH TOOLS' }, |
| 265 | { type: 'tool', name: 'COMPOSIO EXECUTE TOOL' }, |
| 266 | { |
| 267 | type: 'assistant', |
| 268 | content: |
| 269 | 'Triaged 47 errors. 5 classified as P0 — created Linear issues LIN-482 → LIN-486.', |
| 270 | }, |
| 271 | ], |
| 272 | tools: [ |
| 273 | { |
| 274 | kind: 'search', |
| 275 | query: 'list sentry errors and create linear issues', |
| 276 | tools: [ |
| 277 | { |
| 278 | slug: 'sentry', |
| 279 | name: 'SENTRY_LIST_ISSUES', |
| 280 | description: 'List unresolved issues', |
| 281 | }, |
| 282 | { |
| 283 | slug: 'sentry', |
| 284 | name: 'SENTRY_GET_EVENT', |
| 285 | description: 'Get error event details', |
| 286 | }, |
| 287 | { |
| 288 | slug: 'linear', |
| 289 | name: 'LINEAR_CREATE_ISSUE', |
| 290 | description: 'Create a new Linear issue', |
| 291 | }, |
| 292 | ], |
| 293 | }, |
| 294 | { |
| 295 | kind: 'execute', |
| 296 | sessionId: 'sx-4r9b', |
| 297 | tool: 'LINEAR_CREATE_ISSUE', |
| 298 | toolkitSlug: 'linear', |
| 299 | params: [ |
| 300 | { key: 'team', value: 'ENG' }, |
| 301 | { key: 'priority', value: 'P0 (urgent)' }, |
| 302 | { key: 'issues', value: 'LIN-482 → LIN-486' }, |
| 303 | ], |
| 304 | status: '200 OK · 5 issues created', |
| 305 | }, |
| 306 | ], |
| 307 | timeline: [ |
| 308 | { items: [0], toolIdx: null, thinking: false, delay: 900 }, |
| 309 | { items: [0], toolIdx: null, thinking: true, delay: 600 }, |
| 310 | { items: [0, 1], toolIdx: 0, thinking: false, delay: 2400 }, |
| 311 | { items: [0, 1, 2], toolIdx: 1, thinking: false, delay: 2600 }, |
| 312 | { items: [0, 1, 2, 3], toolIdx: null, thinking: false, delay: 2400 }, |
| 313 | ], |
| 314 | }, |
| 315 | ]; |
| 316 | |
| 317 | /** |
| 318 | * v2 right-side mock chat — timeline-driven. Each example walks through |
| 319 | * a step-by-step sequence: user prompt → thinking → tool trail items |
| 320 | * appear one at a time → final assistant response. The floating tool |
| 321 | * overlay is keyed to the current frame's `toolIdx` so it swaps content |
| 322 | * (Search → Workbench → Execute) as the agent uses each one. |
| 323 | * |
| 324 | * The overlay is positioned outside the chat's left edge so it visually |
| 325 | * sits in the middle of the page, half-overlapping the chat boundary. |
| 326 | */ |
| 327 | export function DocsHeroV2Chat() { |
| 328 | const [exampleIdx, setExampleIdx] = useState(0); |
| 329 | const [frameIdx, setFrameIdx] = useState(0); |
| 330 | const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null); |
| 331 | |
| 332 | useEffect(() => { |
| 333 | if (timerRef.current) clearTimeout(timerRef.current); |
| 334 | const example = EXAMPLES[exampleIdx]!; |
| 335 | const timeline = example.timeline; |
| 336 | if (frameIdx >= timeline.length) { |
| 337 | // End of timeline — pause briefly, then advance to the next example. |
| 338 | timerRef.current = setTimeout(() => { |
| 339 | setExampleIdx((i) => (i + 1) % EXAMPLES.length); |
| 340 | setFrameIdx(0); |
| 341 | }, 1200); |
| 342 | } else { |
| 343 | const frame = timeline[frameIdx]!; |
| 344 | timerRef.current = setTimeout(() => { |
| 345 | setFrameIdx((f) => f + 1); |
| 346 | }, frame.delay); |
| 347 | } |
| 348 | return () => { |
| 349 | if (timerRef.current) clearTimeout(timerRef.current); |
| 350 | }; |
| 351 | }, [exampleIdx, frameIdx]); |
| 352 | |
| 353 | const example = EXAMPLES[exampleIdx]!; |
| 354 | const skin = example.skin; |
| 355 | const frame = |
| 356 | example.timeline[Math.min(frameIdx, example.timeline.length - 1)]!; |
| 357 | const visibleItems = frame.items.map((i) => ({ |
| 358 | item: example.chatItems[i]!, |
| 359 | id: `${exampleIdx}-${i}`, |
| 360 | })); |
| 361 | // Always show a tool overlay: fall back to the most recently lit |
| 362 | // tool, or to the first tool of the example before anything fires. |
| 363 | const shownToolIdx = |
| 364 | frame.toolIdx ?? |
| 365 | findLastToolIdx(example.timeline, frameIdx) ?? |
| 366 | 0; |
| 367 | const activeTool = example.tools[shownToolIdx]!; |
| 368 | |
| 369 | return ( |
| 370 | <div className="relative h-full w-full"> |
| 371 | {/* Base chat panel — narrowed and pinned to the right so there's |
| 372 | horizontal room between it and the tool overlay for the L-shape |
| 373 | connector. */} |
| 374 | <div |
| 375 | className="absolute inset-y-0 right-0 flex w-full max-w-[340px] flex-col overflow-hidden border shadow-[0_1px_0_rgba(15,15,15,0.04)] transition-colors duration-300" |
| 376 | style={{ |
| 377 | backgroundColor: skin.bg, |
| 378 | borderColor: skin.borderColor, |
| 379 | borderRadius: skin.radius, |
| 380 | }} |
| 381 | > |
| 382 | {/* Header */} |
| 383 | <div className="flex items-center justify-center gap-2 px-5 py-3"> |
| 384 | <AnimatePresence initial={false} mode="wait"> |
| 385 | <motion.div |
| 386 | key={`hdr-${exampleIdx}`} |
| 387 | animate={{ opacity: 1, y: 0 }} |
| 388 | className="inline-flex items-center gap-2" |
| 389 | exit={{ opacity: 0, y: -6 }} |
| 390 | initial={{ opacity: 0, y: 6 }} |
| 391 | transition={{ duration: 0.25 }} |
| 392 | > |
| 393 | {skin.logo ? ( |
| 394 | <img |
| 395 | alt="" |
| 396 | aria-hidden="true" |
| 397 | className={`h-4 w-4 object-contain ${skin.invertLogo ? 'invert' : ''}`} |
| 398 | draggable={false} |
| 399 | src={skin.logo} |
| 400 | /> |
| 401 | ) : ( |
| 402 | <span |
| 403 | className="size-3 rounded-full" |
| 404 | style={{ backgroundColor: skin.accent }} |
| 405 | /> |
| 406 | )} |
| 407 | <span |
| 408 | className="text-[13px] font-medium" |
| 409 | style={{ color: skin.textColor }} |
| 410 | > |
| 411 | {skin.name} |
| 412 | {skin.subtitle && ( |
| 413 | <span |
| 414 | className="ml-1 font-normal" |
| 415 | style={{ color: skin.textMuted }} |
| 416 | > |
| 417 | {skin.subtitle} |
| 418 | </span> |
| 419 | )} |
| 420 | </span> |
| 421 | </motion.div> |
| 422 | </AnimatePresence> |
| 423 | </div> |
| 424 | |
| 425 | {/* Messages — items animate in one at a time */} |
| 426 | <div className="flex flex-1 flex-col gap-3 overflow-hidden px-5 pt-1 pb-3"> |
| 427 | <AnimatePresence initial={false}> |
| 428 | {visibleItems.map(({ item, id }, i) => { |
| 429 | const isLatest = i === visibleItems.length - 1; |
| 430 | return ( |
| 431 | <motion.div |
| 432 | key={id} |
| 433 | animate={{ opacity: isLatest ? 1 : 0.45, y: 0, scale: 1 }} |
| 434 | exit={{ opacity: 0, scale: 0.97 }} |
| 435 | initial={{ opacity: 0, y: 8, scale: 0.97 }} |
| 436 | layout |
| 437 | transition={{ duration: 0.28, ease: [0.4, 0, 0.2, 1] }} |
| 438 | > |
| 439 | {renderChatItem(item, skin)} |
| 440 | </motion.div> |
| 441 | ); |
| 442 | })} |
| 443 | {frame.thinking && ( |
| 444 | <motion.div |
| 445 | key="thinking" |
| 446 | animate={{ opacity: 1, y: 0 }} |
| 447 | exit={{ opacity: 0 }} |
| 448 | initial={{ opacity: 0, y: 6 }} |
| 449 | layout |
| 450 | transition={{ duration: 0.2 }} |
| 451 | > |
| 452 | <div className="flex gap-1"> |
| 453 | {[0, 1, 2].map((d) => ( |
| 454 | <span |
| 455 | key={d} |
| 456 | className="h-1.5 w-1.5 animate-[pulse-dot_1.4s_ease-in-out_infinite] rounded-full" |
| 457 | style={{ |
| 458 | backgroundColor: skin.accent, |
| 459 | animationDelay: `${d * 0.18}s`, |
| 460 | }} |
| 461 | /> |
| 462 | ))} |
| 463 | </div> |
| 464 | </motion.div> |
| 465 | )} |
| 466 | </AnimatePresence> |
| 467 | </div> |
| 468 | |
| 469 | {/* Input bar */} |
| 470 | <div className="px-3 pb-3"> |
| 471 | <div |
| 472 | className="flex flex-col gap-2 px-4 pt-3 pb-2.5" |
| 473 | style={{ |
| 474 | backgroundColor: skin.inputBg, |
| 475 | borderRadius: `calc(${skin.radius} - 4px)`, |
| 476 | }} |
| 477 | > |
| 478 | <span className="text-[14px]" style={{ color: skin.textMuted }}> |
| 479 | Reply… |
| 480 | </span> |
| 481 | <div className="flex items-center justify-between"> |
| 482 | <svg |
| 483 | fill="none" |
| 484 | height="18" |
| 485 | style={{ color: skin.textMuted }} |
| 486 | viewBox="0 0 18 18" |
| 487 | width="18" |
| 488 | > |
| 489 | <path |
| 490 | d="M9 1.5v15M1.5 9h15" |
| 491 | stroke="currentColor" |
| 492 | strokeLinecap="round" |
| 493 | strokeWidth="1.5" |
| 494 | /> |
| 495 | </svg> |
| 496 | <div className="flex items-center gap-2.5"> |
| 497 | <span |
| 498 | className="text-[12px] leading-none" |
| 499 | style={{ color: skin.textMuted }} |
| 500 | > |
| 501 | {skin.modelLabel} |
| 502 | </span> |
| 503 | <div |
| 504 | className="flex h-7 w-7 items-center justify-center rounded-full" |
| 505 | style={{ backgroundColor: skin.accent }} |
| 506 | > |
| 507 | <svg |
| 508 | fill="none" |
| 509 | height="14" |
| 510 | viewBox="0 0 14 14" |
| 511 | width="14" |
| 512 | > |
| 513 | <path |
| 514 | d="M7 12V2M7 2L3 6M7 2l4 4" |
| 515 | stroke="white" |
| 516 | strokeLinecap="round" |
| 517 | strokeLinejoin="round" |
| 518 | strokeWidth="1.5" |
| 519 | /> |
| 520 | </svg> |
| 521 | </div> |
| 522 | </div> |
| 523 | </div> |
| 524 | </div> |
| 525 | </div> |
| 526 | </div> |
| 527 | |
| 528 | {/* SVG connector — anchored against the chat's left edge. Goes |
| 529 | horizontally left from the chat, then turns down into the top |
| 530 | of the tool overlay. |
| 531 | • Resting state: muted-grey path always visible. |
| 532 | • Active pulse: brand-blue glow + line that "draw" on tool |
| 533 | change and then fade back out, leaving only the grey line. */} |
| 534 | <svg |
| 535 | aria-hidden="true" |
| 536 | className="pointer-events-none absolute z-[5] overflow-visible text-[var(--composio-brand)]" |
| 537 | fill="none" |
| 538 | preserveAspectRatio="none" |
| 539 | style={{ right: '340px', top: '32%', width: '60px', height: '38%' }} |
| 540 | viewBox="0 0 100 100" |
| 541 | > |
| 542 | {/* Inactive grey base line — always present */} |
| 543 | <path |
| 544 | d="M 100 0 H 0 V 100" |
| 545 | stroke="var(--color-fd-foreground)" |
| 546 | strokeLinecap="round" |
| 547 | strokeOpacity="0.22" |
| 548 | strokeWidth="1" |
| 549 | vectorEffect="non-scaling-stroke" |
| 550 | /> |
| 551 | {/* Pulse glow underlay — draws + fades on tool change */} |
| 552 | <motion.path |
| 553 | key={`glow-${exampleIdx}-${shownToolIdx}`} |
| 554 | animate={{ pathLength: 1, opacity: [0, 0.2, 0.2, 0] }} |
| 555 | d="M 100 0 H 0 V 100" |
| 556 | initial={{ pathLength: 0, opacity: 0 }} |
| 557 | stroke="currentColor" |
| 558 | strokeLinecap="round" |
| 559 | strokeWidth={6} |
| 560 | transition={{ |
| 561 | pathLength: { duration: 0.85, ease: [0.4, 0, 0.2, 1] }, |
| 562 | opacity: { duration: 1.4, times: [0, 0.2, 0.7, 1] }, |
| 563 | }} |
| 564 | vectorEffect="non-scaling-stroke" |
| 565 | /> |
| 566 | {/* Pulse bright line — draws + fades on tool change */} |
| 567 | <motion.path |
| 568 | key={`line-${exampleIdx}-${shownToolIdx}`} |
| 569 | animate={{ pathLength: 1, opacity: [0, 1, 1, 0] }} |
| 570 | d="M 100 0 H 0 V 100" |
| 571 | initial={{ pathLength: 0, opacity: 0 }} |
| 572 | stroke="currentColor" |
| 573 | strokeLinecap="round" |
| 574 | strokeWidth={1.5} |
| 575 | transition={{ |
| 576 | pathLength: { duration: 0.85, ease: [0.4, 0, 0.2, 1] }, |
| 577 | opacity: { duration: 1.4, times: [0, 0.2, 0.7, 1] }, |
| 578 | }} |
| 579 | vectorEffect="non-scaling-stroke" |
| 580 | /> |
| 581 | </svg> |
| 582 | |
| 583 | {/* Floating tool overlay — always rendered, anchored near the |
| 584 | bottom of the chat, body content swaps with a fade/slide when |
| 585 | `shownToolIdx` changes. */} |
| 586 | <div className="pointer-events-none absolute bottom-6 left-0 z-10 flex max-h-[60%] -translate-x-[46%] flex-col"> |
| 587 | <div className="flex w-[320px] max-h-full flex-col overflow-hidden rounded-md border border-fd-border bg-fd-card font-mono shadow-[0_24px_48px_-18px_rgba(15,15,15,0.32)]"> |
| 588 | <ActiveToolHeader label={ACTIVE_TOOL_LABELS[activeTool.kind]} /> |
| 589 | <div |
| 590 | className="flex-1 overflow-hidden" |
| 591 | style={{ |
| 592 | maskImage: |
| 593 | 'linear-gradient(to bottom, black 0%, black 80%, transparent 100%)', |
| 594 | WebkitMaskImage: |
| 595 | 'linear-gradient(to bottom, black 0%, black 80%, transparent 100%)', |
| 596 | }} |
| 597 | > |
| 598 | <AnimatePresence initial={false} mode="wait"> |
| 599 | <motion.div |
| 600 | key={`tool-${exampleIdx}-${shownToolIdx}`} |
| 601 | animate={{ opacity: 1, x: 0 }} |
| 602 | exit={{ opacity: 0, x: -8 }} |
| 603 | initial={{ opacity: 0, x: -8 }} |
| 604 | transition={{ duration: 0.28, ease: [0.4, 0, 0.2, 1] }} |
| 605 | > |
| 606 | <ActiveToolBody tool={activeTool} /> |
| 607 | </motion.div> |
| 608 | </AnimatePresence> |
| 609 | </div> |
| 610 | </div> |
| 611 | </div> |
| 612 | </div> |
| 613 | ); |
| 614 | } |
| 615 | |
| 616 | function renderChatItem(item: ChatItem, skin: ChatSkin) { |
| 617 | if (item.type === 'user') { |
| 618 | return ( |
| 619 | <div className="flex justify-end"> |
| 620 | <div |
| 621 | className="max-w-[85%] px-4 py-2.5 text-[14px] leading-relaxed" |
| 622 | style={{ |
| 623 | backgroundColor: skin.userBubbleBg, |
| 624 | color: skin.textColor, |
| 625 | borderRadius: `calc(${skin.radius} - 4px)`, |
| 626 | }} |
| 627 | > |
| 628 | {item.content} |
| 629 | </div> |
| 630 | </div> |
| 631 | ); |
| 632 | } |
| 633 | if (item.type === 'tool') { |
| 634 | return ( |
| 635 | <div className="inline-flex items-center gap-1 text-[12px] uppercase tracking-wider hero-tool-shimmer"> |
| 636 | <span className="font-medium">{item.name}</span> |
| 637 | <svg |
| 638 | aria-hidden="true" |
| 639 | className="h-3 w-3" |
| 640 | fill="none" |
| 641 | viewBox="0 0 12 12" |
| 642 | > |
| 643 | <path |
| 644 | d="M4 3l3 3-3 3" |
| 645 | stroke="currentColor" |
| 646 | strokeLinecap="round" |
| 647 | strokeLinejoin="round" |
| 648 | strokeWidth="1.5" |
| 649 | /> |
| 650 | </svg> |
| 651 | </div> |
| 652 | ); |
| 653 | } |
| 654 | return ( |
| 655 | <p |
| 656 | className="text-[15px] leading-relaxed" |
| 657 | style={{ color: skin.textColor }} |
| 658 | > |
| 659 | {item.content} |
| 660 | </p> |
| 661 | ); |
| 662 | } |
| 663 | |
| 664 | function ActiveToolHeader({ label }: { label: string }) { |
| 665 | return ( |
| 666 | <div className="flex items-center justify-between border-b border-fd-border px-3 py-1.5 text-[10px]"> |
| 667 | <span className="uppercase tracking-[0.04em] text-fd-foreground/45"> |
| 668 | {label} |
| 669 | </span> |
| 670 | <span className="inline-flex items-center gap-1 text-[var(--composio-brand)]"> |
| 671 | <span className="relative inline-flex"> |
| 672 | <span className="size-1.5 rounded-full bg-[var(--composio-brand)]" /> |
| 673 | <span className="absolute inset-0 animate-ping rounded-full bg-[var(--composio-brand)] opacity-60" /> |
| 674 | </span> |
| 675 | <span className="uppercase tracking-[0.04em]">running</span> |
| 676 | </span> |
| 677 | </div> |
| 678 | ); |
| 679 | } |
| 680 | |
| 681 | function ActiveToolBody({ tool }: { tool: ActiveTool }) { |
| 682 | if (tool.kind === 'search') return <SearchToolBody tool={tool} />; |
| 683 | if (tool.kind === 'execute') return <ExecuteToolBody tool={tool} />; |
| 684 | return <WorkbenchToolBody tool={tool} />; |
| 685 | } |
| 686 | |
| 687 | function SearchToolBody({ |
| 688 | tool, |
| 689 | }: { |
| 690 | tool: Extract<ActiveTool, { kind: 'search' }>; |
| 691 | }) { |
| 692 | return ( |
| 693 | <div className="flex flex-col gap-2 px-3 py-2.5"> |
| 694 | <div className="flex items-center gap-2 border border-fd-border bg-fd-background px-2 py-1"> |
| 695 | <svg |
| 696 | aria-hidden="true" |
| 697 | className="size-3 text-fd-foreground/40" |
| 698 | fill="none" |
| 699 | viewBox="0 0 12 12" |
| 700 | > |
| 701 | <circle |
| 702 | cx="5.25" |
| 703 | cy="5.25" |
| 704 | r="3.75" |
| 705 | stroke="currentColor" |
| 706 | strokeWidth="1" |
| 707 | /> |
| 708 | <path |
| 709 | d="M8 8l2.5 2.5" |
| 710 | stroke="currentColor" |
| 711 | strokeLinecap="round" |
| 712 | strokeWidth="1" |
| 713 | /> |
| 714 | </svg> |
| 715 | <span className="truncate text-[10.5px] text-fd-foreground/65"> |
| 716 | {tool.query} |
| 717 | </span> |
| 718 | <span className="ml-auto shrink-0 text-[10px] text-fd-foreground/35"> |
| 719 | {tool.tools.length} found |
| 720 | </span> |
| 721 | </div> |
| 722 | <div className="flex flex-col gap-1"> |
| 723 | {tool.tools.slice(0, 3).map((t) => ( |
| 724 | <div |
| 725 | key={t.name} |
| 726 | className="flex items-center gap-2 border border-fd-border bg-fd-background px-2 py-1.5" |
| 727 | > |
| 728 | <img |
| 729 | alt="" |
| 730 | aria-hidden="true" |
| 731 | className="size-3.5 object-contain" |
| 732 | draggable={false} |
| 733 | src={`${LOGO_CDN}/${t.slug}`} |
| 734 | /> |
| 735 | <div className="flex min-w-0 flex-col"> |
| 736 | <span className="truncate text-[10.5px] text-fd-foreground/75"> |
| 737 | {t.name} |
| 738 | </span> |
| 739 | <span className="truncate text-[9.5px] text-fd-foreground/45"> |
| 740 | {t.description} |
| 741 | </span> |
| 742 | </div> |
| 743 | </div> |
| 744 | ))} |
| 745 | </div> |
| 746 | </div> |
| 747 | ); |
| 748 | } |
| 749 | |
| 750 | function ExecuteToolBody({ |
| 751 | tool, |
| 752 | }: { |
| 753 | tool: Extract<ActiveTool, { kind: 'execute' }>; |
| 754 | }) { |
| 755 | return ( |
| 756 | <div className="flex flex-col gap-2 px-3 py-2.5"> |
| 757 | <div className="text-[10px] text-fd-foreground/40"> |
| 758 | SESSION: {tool.sessionId} |
| 759 | </div> |
| 760 | <div className="flex items-center gap-2 border border-fd-border bg-fd-background px-2 py-1.5"> |
| 761 | <img |
| 762 | alt="" |
| 763 | aria-hidden="true" |
| 764 | className="size-3.5 object-contain" |
| 765 | draggable={false} |
| 766 | src={`${LOGO_CDN}/${tool.toolkitSlug}`} |
| 767 | /> |
| 768 | <span className="truncate text-[10.5px] text-fd-foreground/75"> |
| 769 | {tool.tool} |
| 770 | </span> |
| 771 | </div> |
| 772 | <div className="flex flex-col gap-1 border border-fd-border bg-fd-background px-2 py-1.5"> |
| 773 | {tool.params.map((p) => ( |
| 774 | <div |
| 775 | key={p.key} |
| 776 | className="flex items-center justify-between text-[10px]" |
| 777 | > |
| 778 | <span className="text-fd-foreground/45">{p.key}</span> |
| 779 | <span className="text-fd-foreground/75">{p.value}</span> |
| 780 | </div> |
| 781 | ))} |
| 782 | </div> |
| 783 | <div className="flex items-center gap-1.5 text-[10px] text-[var(--composio-brand)]"> |
| 784 | <svg |
| 785 | aria-hidden="true" |
| 786 | className="size-3" |
| 787 | fill="none" |
| 788 | viewBox="0 0 12 12" |
| 789 | > |
| 790 | <path |
| 791 | d="M2.5 6l2.5 2.5L9.5 3.5" |
| 792 | stroke="currentColor" |
| 793 | strokeLinecap="round" |
| 794 | strokeLinejoin="round" |
| 795 | strokeWidth="1.6" |
| 796 | /> |
| 797 | </svg> |
| 798 | <span>{tool.status}</span> |
| 799 | </div> |
| 800 | </div> |
| 801 | ); |
| 802 | } |
| 803 | |
| 804 | function WorkbenchToolBody({ |
| 805 | tool, |
| 806 | }: { |
| 807 | tool: Extract<ActiveTool, { kind: 'workbench' }>; |
| 808 | }) { |
| 809 | return ( |
| 810 | <div className="flex flex-col bg-fd-muted"> |
| 811 | <div className="flex items-center justify-between gap-2 border-b border-fd-border px-3 py-1.5"> |
| 812 | <div className="flex min-w-0 items-center gap-2"> |
| 813 | <CpuLightsStatic /> |
| 814 | <span className="truncate text-[9.5px] uppercase tracking-wider text-fd-foreground/55"> |
| 815 | {tool.task} |
| 816 | </span> |
| 817 | </div> |
| 818 | <span className="shrink-0 text-[9px] uppercase tracking-wider text-[var(--composio-brand)]"> |
| 819 | {tool.result ? 'done' : 'running'} |
| 820 | </span> |
| 821 | </div> |
| 822 | <div |
| 823 | className="relative overflow-hidden px-3 py-2" |
| 824 | style={{ |
| 825 | maskImage: |
| 826 | 'linear-gradient(to bottom, black 0%, black 70%, transparent 100%)', |
| 827 | WebkitMaskImage: |
| 828 | 'linear-gradient(to bottom, black 0%, black 70%, transparent 100%)', |
| 829 | }} |
| 830 | > |
| 831 | <pre className="overflow-hidden text-[10px] leading-[1.55] text-fd-foreground/65"> |
| 832 | {tool.code} |
| 833 | </pre> |
| 834 | </div> |
| 835 | </div> |
| 836 | ); |
| 837 | } |
| 838 | |
| 839 | function CpuLightsStatic() { |
| 840 | const cells = Array.from({ length: 8 }); |
| 841 | return ( |
| 842 | <div |
| 843 | className="grid shrink-0 gap-[1px]" |
| 844 | style={{ |
| 845 | gridTemplateColumns: 'repeat(4, 4px)', |
| 846 | gridTemplateRows: 'repeat(2, 4px)', |
| 847 | }} |
| 848 | > |
| 849 | {cells.map((_, i) => { |
| 850 | const col = i % 4; |
| 851 | const row = Math.floor(i / 4); |
| 852 | const delay = (col * 120 + row * 60) % 720; |
| 853 | return ( |
| 854 | <span |
| 855 | key={i} |
| 856 | className="bg-[var(--composio-brand)]" |
| 857 | style={{ |
| 858 | animation: `hero-cpu-pulse 1.4s ease-in-out ${delay}ms infinite`, |
| 859 | }} |
| 860 | /> |
| 861 | ); |
| 862 | })} |
| 863 | </div> |
| 864 | ); |
| 865 | } |