"use client"; import { BombIcon, ListIcon, PaletteIcon, PenLineIcon, PenSquareIcon, Trash2Icon, XIcon, } from "lucide-react"; import { type ReactNode, useEffect, useRef } from "react"; import { cn } from "@/lib/utils"; export type SlashCommand = { name: string; description: string; icon: ReactNode; action: string; shortcut?: string; }; export const slashCommands: SlashCommand[] = [ { name: "new", description: "Start a new chat", icon: , action: "new", }, { name: "clear", description: "Clear current chat", icon: , action: "clear", }, { name: "rename", description: "Rename current chat", icon: , action: "rename", }, { name: "model", description: "Change the AI model", icon: , action: "model", }, { name: "theme", description: "Toggle dark/light mode", icon: , action: "theme", }, { name: "delete", description: "Delete current chat", icon: , action: "delete", }, { name: "purge", description: "Delete all chats", icon: , action: "purge", }, ]; type SlashCommandMenuProps = { query: string; onSelect: (command: SlashCommand) => void; onClose: () => void; selectedIndex: number; }; export function SlashCommandMenu({ query, onSelect, onClose: _onClose, selectedIndex, }: SlashCommandMenuProps) { const menuRef = useRef(null); const filtered = slashCommands.filter((cmd) => cmd.name.startsWith(query.toLowerCase()) ); useEffect(() => { const selected = menuRef.current?.querySelector("[data-selected='true']"); if (selected) { selected.scrollIntoView({ block: "nearest" }); } }, []); if (filtered.length === 0) { return null; } return ( Commands {filtered.map((cmd, index) => ( onSelect(cmd)} onMouseDown={(e) => e.preventDefault()} type="button" > {cmd.icon} /{cmd.name} {cmd.description} {cmd.shortcut && ( {cmd.shortcut} )} ))} ); }