"use client"; import { appStore } from "@/app/store"; import { getShortcutKeyList, isShortcutEvent, Shortcuts, } from "lib/keyboard-shortcuts"; import { Check, CheckIcon, ClipboardCheck, Infinity, PenOff, Settings2, } from "lucide-react"; import { useEffect, useState } from "react"; import { Button } from "ui/button"; import { useTranslations } from "next-intl"; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger, } from "ui/dropdown-menu"; import { useShallow } from "zustand/shallow"; import { Tooltip, TooltipContent, TooltipTrigger } from "ui/tooltip"; import { capitalizeFirstLetter, cn, createDebounce } from "lib/utils"; const debounce = createDebounce(); export const ToolModeDropdown = ({ disabled }: { disabled?: boolean }) => { const t = useTranslations("Chat.Tool"); const [toolChoice, appStoreMutate] = appStore( useShallow((state) => [state.toolChoice, state.mutate]), ); const [open, setOpen] = useState(false); const [toolChoiceChangeInfo, setToolChoiceChangeInfo] = useState(false); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (isShortcutEvent(e, Shortcuts.toolMode)) { e.preventDefault(); e.stopPropagation(); appStoreMutate(({ toolChoice }) => { return { toolChoice: toolChoice == "auto" ? "manual" : toolChoice == "manual" ? "none" : "auto", }; }); setToolChoiceChangeInfo(true); debounce(() => { setToolChoiceChangeInfo(false); }, 1000); } }; window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, []); return (
{capitalizeFirstLetter(toolChoice)} {t("selectToolMode")} {getShortcutKeyList(Shortcuts.toolMode).join("")}
{t("selectToolMode")} {getShortcutKeyList(Shortcuts.toolMode).join("")} appStoreMutate({ toolChoice: "auto" })} >
{t("auto")} {toolChoice == "auto" && }

{t("autoToolModeDescription")}

appStoreMutate({ toolChoice: "manual" })} >
{t("manual")} {toolChoice == "manual" && }

{t("manualToolModeDescription")}

appStoreMutate({ toolChoice: "none" })} >
{t("none")} {t("mentionOnly")} {toolChoice == "none" && }

{t("noneToolModeDescription")}

); };