import { useMemo, useRef, useState } from 'react'; import type { ComponentType } from 'react'; import type { LucideProps } from 'lucide-react'; import { ArrowUpRight, Search } from 'lucide-react'; export type WorkbenchAction = { id: string; label: string; description: string; group: string; icon: ComponentType; run: () => void; disabled?: boolean; reason?: string }; export function WorkbenchTools({ actions, onClose }: { actions: WorkbenchAction[]; onClose: () => void }) { const [query, setQuery] = useState(''); const list = useRef(null); const filtered = useMemo(() => actions.filter(action => (action.label + action.description + action.group).toLocaleLowerCase().includes(query.trim().toLocaleLowerCase())), [actions, query]); return
setQuery(event.target.value)} placeholder="搜索工具、文件或任务操作…" onKeyDown={event => { if (event.key === 'ArrowDown') { event.preventDefault(); list.current?.querySelector('button:not(:disabled)')?.focus(); } if (event.key === 'Enter') { const first = filtered.find(action => !action.disabled); if (first) { onClose(); first.run(); } } }} />Esc
{ if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) return; const buttons = Array.from(list.current?.querySelectorAll('button:not(:disabled)') ?? []); if (!buttons.length) return; event.preventDefault(); const index = buttons.indexOf(document.activeElement as HTMLButtonElement); buttons[event.key === 'Home' ? 0 : event.key === 'End' ? buttons.length - 1 : (index + (event.key === 'ArrowDown' ? 1 : -1) + buttons.length) % buttons.length]?.focus(); }}> {[...new Set(filtered.map(action => action.group))].map(group =>

{group}

{filtered.filter(action => action.group === group).map(action => )}
)} {!filtered.length &&
没有找到“{query}”

试试“模型”“文件”或“研究”。

}
↑ ↓ 选择工具 · Enter 打开Ctrl K 随时唤起
; }