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, useSyncExternalStore } from 'react'; |
| 4 | import { Search, MessageSquare } from 'lucide-react'; |
| 5 | import { useTranslations } from '@fuma-translate/react'; |
| 6 | import { useSearchContext } from 'fumadocs-ui/contexts/search'; |
| 7 | |
| 8 | import { toggleEveChat } from './eve-chat-store'; |
| 9 | |
| 10 | export function detectMac(): boolean { |
| 11 | try { |
| 12 | if ('userAgentData' in navigator) { |
| 13 | const platform = (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData?.platform; |
| 14 | if (platform) { |
| 15 | return platform === 'macOS'; |
| 16 | } |
| 17 | } |
| 18 | return /mac/i.test(navigator.platform); |
| 19 | } catch { |
| 20 | return true; // default to Mac |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | function useIsMac() { |
| 25 | return useSyncExternalStore( |
| 26 | () => () => {}, |
| 27 | detectMac, |
| 28 | () => true, |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | const handleKeyDown = (e: KeyboardEvent) => { |
| 33 | if ((e.metaKey || e.ctrlKey) && e.key === 'i') { |
| 34 | e.preventDefault(); |
| 35 | toggleEveChat(); |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | function useAskAIShortcut() { |
| 40 | useEffect(() => { |
| 41 | document.addEventListener('keydown', handleKeyDown); |
| 42 | return () => document.removeEventListener('keydown', handleKeyDown); |
| 43 | }, []); |
| 44 | } |
| 45 | |
| 46 | /** Desktop: search bar + Ask AI button side by side */ |
| 47 | export function SearchAndAskAI() { |
| 48 | const { enabled, hotKey, setOpenSearch } = useSearchContext(); |
| 49 | const t = useTranslations({ note: 'search trigger' }); |
| 50 | useAskAIShortcut(); |
| 51 | const isMac = useIsMac(); |
| 52 | |
| 53 | return ( |
| 54 | <> |
| 55 | {enabled && ( |
| 56 | <button |
| 57 | type="button" |
| 58 | data-search-full="" |
| 59 | className="inline-flex items-center gap-2 rounded-none border bg-fd-secondary/50 p-1.5 ps-2.5 text-sm text-fd-muted-foreground transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground w-full max-w-[240px]" |
| 60 | onClick={() => setOpenSearch(true)} |
| 61 | > |
| 62 | <Search className="size-4" /> |
| 63 | {t('Search')} |
| 64 | <div className="ms-auto inline-flex gap-0.5"> |
| 65 | {hotKey.map((k, i) => ( |
| 66 | <kbd key={i} className="rounded-md border bg-fd-background px-1.5"> |
| 67 | {k.display} |
| 68 | </kbd> |
| 69 | ))} |
| 70 | </div> |
| 71 | </button> |
| 72 | )} |
| 73 | <button |
| 74 | type="button" |
| 75 | onClick={() => { |
| 76 | toggleEveChat(); |
| 77 | }} |
| 78 | className="inline-flex items-center gap-2 rounded-lg border border-[var(--composio-orange)]/20 bg-[var(--composio-orange)]/5 p-1.5 ps-2.5 text-sm text-[var(--composio-orange)] transition-colors hover:bg-[var(--composio-orange)]/10 shrink-0" |
| 79 | > |
| 80 | Ask AI |
| 81 | <div className="hidden lg:inline-flex gap-0.5"> |
| 82 | <kbd className="rounded-md border bg-fd-background px-1.5">{isMac ? '⌘' : 'Ctrl'}</kbd> |
| 83 | <kbd className="rounded-md border bg-fd-background px-1.5">I</kbd> |
| 84 | </div> |
| 85 | </button> |
| 86 | </> |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | /** Mobile: search icon + Ask AI icon, shown below lg breakpoint */ |
| 91 | export function SearchAndAskAIMobile() { |
| 92 | const { enabled, setOpenSearch } = useSearchContext(); |
| 93 | |
| 94 | return ( |
| 95 | <> |
| 96 | {enabled && ( |
| 97 | <button |
| 98 | type="button" |
| 99 | data-search="" |
| 100 | aria-label="Open Search" |
| 101 | className="inline-flex items-center justify-center rounded-md p-2 text-sm font-medium transition-colors duration-100 hover:bg-fd-accent hover:text-fd-accent-foreground" |
| 102 | onClick={() => setOpenSearch(true)} |
| 103 | > |
| 104 | <Search className="size-4.5" /> |
| 105 | </button> |
| 106 | )} |
| 107 | <button |
| 108 | type="button" |
| 109 | aria-label="Ask AI" |
| 110 | onClick={() => { |
| 111 | toggleEveChat(); |
| 112 | }} |
| 113 | className="inline-flex items-center justify-center rounded-md p-2 text-sm font-medium transition-colors duration-100 hover:bg-fd-accent hover:text-fd-accent-foreground" |
| 114 | > |
| 115 | <MessageSquare className="size-4.5" /> |
| 116 | </button> |
| 117 | </> |
| 118 | ); |
| 119 | } |